I currently cache the result of a method invocation.
The caching code follows the standard pattern: it uses the item in the cache if it exists, otherwise it calculates the result, caching it for future calls before returning it.
I would like to shield client code from cache misses (e.g. when the item has expired).
I am thinking of spawning a thread to wait for the lifetime of the cached object, to then run a supplied function to repopulate the cache when (or just before) the existing item expires.
Can anyone share any experience related to this? Does this sound like a sensible approach?
I’m using .NET 4.0.
Since this is ASP.NET, the
Cache.Insert()method allows you to specify a callback delegate.Yes, the callback (and File-dependency) are supplied for exactly this kind of situation. You still have ro make a trade of between resources, latency and out-of-dateness.