Extension methods for setting up caches using Microsoft.Extensions.DependencyInjection.
To use with an IServiceCollection
instance at startup:
services.AddLru<int, string>(builder =>
builder
.WithCapacity(666)
.Build());
This adds a ConcurrentLru
where the key is an integer and the cached value is a string. The builder delegate is used to configure the registered cache with a capacity of 666, see the wiki for more details about the builder API and configurable cache features.
There is an extension method for each cache interface:
Extension | Result |
---|---|
AddLru<TKey, TValue> |
Registers ConcurrentLru<TKey, TValue> as a singleton ICache<TKey, TValue> |
AddAsyncLru<TKey, TValue> |
Registers ConcurrentLru<TKey, TValue> as a singleton IAsyncCache<TKey, TValue> |
AddScopedLru<TKey, TValue> |
Registers ConcurrentLru<TKey, TValue> as a singleton IScopedCache<TKey, TValue> |
AddScopedAsyncLru<TKey, TValue> |
Registers ConcurrentLru<TKey, TValue> as a singleton IScopedAsyncCache<TKey, TValue> |
To use with an IServiceCollection
instance at startup:
services.AddLfu<int, string>(builder =>
builder
.WithCapacity(666)
.Build());
This adds a ConcurrentLfu
where the key is an integer and the cached value is a string. The builder delegate is used to configure the registered cache with a capacity of 666, see the wiki for more details about the builder API and configurable cache features.
There is an extension method for each cache interface:
Extension | Result |
---|---|
AddLfu<TKey, TValue> |
Registers ConcurrentLfu<TKey, TValue> as a singleton ICache<TKey, TValue> |
AddAsyncLfu<TKey, TValue> |
Registers ConcurrentLfu<TKey, TValue> as a singleton IAsyncCache<TKey, TValue> |
AddScopedLfu<TKey, TValue> |
Registers ConcurrentLfu<TKey, TValue> as a singleton IScopedCache<TKey, TValue> |
AddScopedAsyncLfu<TKey, TValue> |
Registers ConcurrentLfu<TKey, TValue> as a singleton IScopedAsyncCache<TKey, TValue> |