Skip to content

MemoryCache wrapper which helps reduce cached slow function calls.

Notifications You must be signed in to change notification settings

cliechty/AsyncCache

Repository files navigation

Build status

Async Cache

.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.

Installation

Install using nuget. The Package is named AsyncCache (not yet available)

Usage

Adding and Retriving Values

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.

Removing Values

Cacher.Remove(cacheKey: "theKey");

Todo

  • Documentation
  • Example project / demo

About

MemoryCache wrapper which helps reduce cached slow function calls.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published