ZiggyCreatures / FusionCache

FusionCache is an easy to use, fast and robust hybrid cache with advanced resiliency features.
MIT License
1.79k stars 92 forks source link

[FEATURE] Provide heartbeat feedback possibility from factory for complementing timeouts #325

Open zorgoz opened 1 day ago

zorgoz commented 1 day ago

Problem

Some factories take really long time to run. Like fetching all users from a tenant from AzureAD. That's why they need to be cached. GraphAPI provides paginated fetch possibility only - that makes sense. Hence the data is produced in chunks. Each chunk can time out on its own, but the complete batch can take much-much longer. Setting a long timeout for the whole factory is not resilient enough.

Solution

If there is a way to signal from the producer that the factory is still working properly, it could reset the timeout timer.

Proposal

An overload for each core method that takes a factory, where the factory is Fun<IHeartbeatSignal, T> and Fun<IHeartbeatSignal, CancellationToken, Task<T>> respectively

public interface IHeartbeatSignal
{
       void Signal();
}

The factory should call this method to reset the timeout counter. If the signal does not arrive within the timeout period, the factory is considered to be in timeout and handled accordingly based on failsafe setup and async version.

jodydonetti commented 11 hours ago

Hi @zorgoz , this is in fact an interesting idea! Not straightforward to implement, but still: let me think about it (including potential ramifications, edge cases and whatnot), will get back to you. Thanks!