VLobyntsev.FluentCaching
0.0.2
See the version list below for details.
dotnet add package VLobyntsev.FluentCaching --version 0.0.2
NuGet\Install-Package VLobyntsev.FluentCaching -Version 0.0.2
<PackageReference Include="VLobyntsev.FluentCaching" Version="0.0.2" />
paket add VLobyntsev.FluentCaching --version 0.0.2
#r "nuget: VLobyntsev.FluentCaching, 0.0.2"
// Install VLobyntsev.FluentCaching as a Cake Addin
#addin nuget:?package=VLobyntsev.FluentCaching&version=0.0.2
// Install VLobyntsev.FluentCaching as a Cake Tool
#tool nuget:?package=VLobyntsev.FluentCaching&version=0.0.2
Code samples
Configure caching policy by entity and build cache object
var cache = new CacheBuilder()
.For<User>(u => u.UseAsKey("user").CombinedWith(u => u.Id) // alternatively UseAsKey(u => $"user{u.Id}")
.And().SetExpirationTimeoutTo(2).Minutes.And(10).Seconds
.With().SlidingExpiration())
.Build();
Add object to cache
var user = _userService.GetUserById(42);
await cache.CacheAsync(user);
Retrieve object from cache
var userId = 42;
await cache.RetrieveAsync<User>(userId);
Remove object from cache
var userId = 42;
await cache.RemoveAsync<User>(userId);
Multi property configuration is supported with the same set of features
var cache = new CacheBuilder()
.For<User>(u => u.UseAsKey(u => u.FirstName).CombinedWith(u => u.LastName) // alternatively UseAsKey(u => u.FirstName + u.LastName)
.And().SetExpirationTimeoutTo(2).Minutes.And(10).Seconds
.With().SlidingExpiration())
.Build();
var userKey = new {FirstName = "John", LastName = "Doe"}; // may be any class or struct with corresponding properties
await cache.RetrieveAsync<User>(userKey);
Different cache implementations for different entities are supported
var cache = new CacheBuilder()
.For<User>(u => u.UseAsKey(u => u.FirstName).CombinedWith(u => u.LastName)
.And().SetExpirationTimeoutTo(2).Minutes.And(10).Seconds
.With().AbsoluteExpiration().And().StoreInMemory())
.For<Order>(o => o.UseAsKey(o => o.Date).CombinedWith("order")
.And().SetInfiniteExpirationTimeout()
.And().StoreInDistributedCache())
.Build();
Current benchmarks
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.19045
Intel Core i5-9300H CPU 2.40GHz, 1 CPU, 8 logical and 4 physical cores
.NET Core SDK=7.0.202
[Host] : .NET Core 6.0.9 (CoreCLR 6.0.922.41905, CoreFX 6.0.922.41905), X64 RyuJIT
DefaultJob : .NET Core 6.0.9 (CoreCLR 6.0.922.41905, CoreFX 6.0.922.41905), X64 RyuJIT
Method | ItemsCount | Mean | Error | StdDev | Median | Allocated |
---|---|---|---|---|---|---|
CacheWithComplexKey | 100 | 0.3616 ms | 0.0455 ms | 0.1340 ms | 0.3616 ms | 53.72 KB |
RetrieveWithComplexKey | 100 | 0.0924 ms | 0.0018 ms | 0.0027 ms | 0.0919 ms | 47.27 KB |
CacheWithSimpleKey | 100 | 0.0821 ms | 0.0051 ms | 0.0148 ms | 0.0736 ms | 48.13 KB |
RetrieveWithSimpleKey | 100 | 0.0656 ms | 0.0013 ms | 0.0015 ms | 0.0652 ms | 38.75 KB |
CacheWithComplexKey | 1000 | 1.0152 ms | 0.0473 ms | 0.1349 ms | 0.9603 ms | 530.86 KB |
RetrieveWithComplexKey | 1000 | 1.0323 ms | 0.0519 ms | 0.1522 ms | 0.9536 ms | 476.17 KB |
CacheWithSimpleKey | 1000 | 0.9037 ms | 0.0436 ms | 0.1251 ms | 0.8571 ms | 484.06 KB |
RetrieveWithSimpleKey | 1000 | 0.6686 ms | 0.0088 ms | 0.0078 ms | 0.6677 ms | 390.32 KB |
CacheWithComplexKey | 10000 | 14.1614 ms | 0.4543 ms | 1.2437 ms | 13.6662 ms | 5382.46 KB |
RetrieveWithComplexKey | 10000 | 10.6172 ms | 0.5431 ms | 1.5139 ms | 9.8729 ms | 4835.57 KB |
CacheWithSimpleKey | 10000 | 12.1970 ms | 0.2404 ms | 0.5713 ms | 12.0789 ms | 4845.48 KB |
RetrieveWithSimpleKey | 10000 | 6.8092 ms | 0.1594 ms | 0.4471 ms | 6.6842 ms | 3905.95 KB |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net7.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on VLobyntsev.FluentCaching:
Package | Downloads |
---|---|
VLobyntsev.FluentCaching.DependencyInjection
Microsoft.Extensions.DependencyInjection integration for fluent caching |
|
VLobyntsev.FluentCaching.Memory
Memory cache integration for fluent caching |
|
VLobyntsev.FluentCaching.DistributedCache
Distributed cache integration for fluent caching |
GitHub repositories
This package is not used by any popular GitHub repositories.