https://github.com/bitfaster/bitfaster.caching.dependencyinjection
Extension methods for setting up caches using Microsoft.Extensions.DependencyInjection.
https://github.com/bitfaster/bitfaster.caching.dependencyinjection
Last synced: 8 months ago
JSON representation
Extension methods for setting up caches using Microsoft.Extensions.DependencyInjection.
- Host: GitHub
- URL: https://github.com/bitfaster/bitfaster.caching.dependencyinjection
- Owner: bitfaster
- License: mit
- Created: 2022-09-30T21:42:15.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-09-04T12:08:19.000Z (over 2 years ago)
- Last Synced: 2025-08-24T10:16:04.860Z (9 months ago)
- Language: C#
- Size: 59.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BitFaster.Caching.DependencyInjection
Extension methods for setting up [caches](https://github.com/bitfaster/BitFaster.Caching/wiki/Caches) using [Microsoft.Extensions.DependencyInjection](https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/).
[](https://badge.fury.io/nu/BitFaster.Caching.DependencyInjection)


[](https://coveralls.io/github/bitfaster/BitFaster.Caching.DependencyInjection?branch=main)
# ConcurrentLru
To use with an `IServiceCollection` instance at startup:
```cs
services.AddLru(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](https://github.com/bitfaster/BitFaster.Caching/wiki/ConcurrentLru-Quickstart#builder-api) for more details about the builder API and configurable cache features.
There is an extension method for each [cache interface](https://github.com/bitfaster/BitFaster.Caching/wiki/Caches):
| Extension | Result |
|-----------|--------|
| `AddLru` | Registers `ConcurrentLru` as a singleton `ICache` |
| `AddAsyncLru` | Registers `ConcurrentLru` as a singleton `IAsyncCache` |
| `AddScopedLru` | Registers `ConcurrentLru` as a singleton `IScopedCache` |
| `AddScopedAsyncLru` | Registers `ConcurrentLru` as a singleton `IScopedAsyncCache` |
# ConcurrentLfu
To use with an `IServiceCollection` instance at startup:
```cs
services.AddLfu(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](https://github.com/bitfaster/BitFaster.Caching/wiki/ConcurrentLfu-Quickstart#builder-api) for more details about the builder API and configurable cache features.
There is an extension method for each [cache interface](https://github.com/bitfaster/BitFaster.Caching/wiki/Caches):
| Extension | Result |
|-----------|--------|
| `AddLfu` | Registers `ConcurrentLfu` as a singleton `ICache` |
| `AddAsyncLfu` | Registers `ConcurrentLfu` as a singleton `IAsyncCache` |
| `AddScopedLfu` | Registers `ConcurrentLfu` as a singleton `IScopedCache` |
| `AddScopedAsyncLfu` | Registers `ConcurrentLfu` as a singleton `IScopedAsyncCache` |