-
Notifications
You must be signed in to change notification settings - Fork 39
Caches
BitFaster.Caching provides in memory caches that implement the following interfaces:
ICacheIAsyncCacheIScopedCacheIScopedAsyncCache
ICache is similar to IDictionary, but with the addition of a cache policy, optional metrics and optional events. IAsyncCache is essentially the same, but with a GetOrAddAsync method in place of GetOrAdd. IAsyncCache is distinct to avoid the pitfalls of Sync over Async (deadlocks) and Async over Sync (scalability).
IScopedCache makes it easy to work with Scoped values. In place of ICache.GetOrAdd it instead provides ScopedGetOrAdd which returns a lifetime rather than a value. Internally, ScopedGetOrAdd safely resolves races between concurrent reads and deletes. IScopedAsyncCache is the async equivalent.
ConcurrentLru and ConcurrentLfu implement both ICache and IAsyncCache, since internally they do not mix sync and async logic. This gives the programmer most flexibility, enabling a mix of sync and async only when it is safe to do so.