bitfaster / BitFaster.Caching.DependencyInjection

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

License:MIT License


Languages

Language:C# 100.0%