Skip to content

Extension methods for setting up caches using Microsoft.Extensions.DependencyInjection.

License

Notifications You must be signed in to change notification settings

bitfaster/BitFaster.Caching.DependencyInjection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BitFaster.Caching.DependencyInjection

Extension methods for setting up caches using Microsoft.Extensions.DependencyInjection.

NuGet version Nuget .NET Core Coverage Status

ConcurrentLru

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>

ConcurrentLfu

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>

About

Extension methods for setting up caches using Microsoft.Extensions.DependencyInjection.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages