You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Feature request: When caching a Result or Option: soft and hard timeouts, to have the ability to return the expired cache value if the operation fails #92
In some cases it may be worthwile to fall back to the cached, but expired value if the function is not successful in computing the current value of the thing to be cached.
For example a function retrieves some rarely changing value over the network, and caches it for say 1 day. In case the thing is requested after 24 hours and 1 minute, the cache is expired, so we attempt to retrieve it again. In case the retrieval fails (because network is down, server is down, etc.), one may assume that the old cached value is probably still valid, and I'd like to have it return it. This would basically make the function infallible though I'm not sure we can express that using the type system as the function itself needs to be able to return a failure to communicate to the cache that it needs to return the cached value even though it is expired.
One step further and adding more flexibility would be to add a "soft" and a "hard" timeout for the cached values. After the soft timeout the operation to calculate the value is attempted again, but if it fails the cached value is returned. After the hard timeout the cached value is not returned at all.