.net Memory Cache wrapper that offloads refreshing cached values to background threads without blocking the caller. This library is useful for caching operations which are time consuming and/or the results don't change often.
Install using nuget. The Package is named AsyncCache (not yet available)
Adding and retriving cached values uses the same function call.
String value = Cacher.Get(cacheKey: "theKey",
cachedOperation: () => someSlowFunctionCall("parameter"),
refreshIn: Timespan.FromMinutes(10));
The code above will request the value for 'theKey' in the cache.
If the value is cached, then the cached value is returned.
If the value is not cached, the cachedOperation Func will be called to supply and cache the value.
If refresh time has passed, then the currently cached value is returned and the cachedOperation Func will be called in a background thread to refresh the cached value.
Cacher.Remove(cacheKey: "theKey");
- Documentation
- Example project / demo