LiteDb.Extensions.Caching 2.2.0

.NET 6.0 .NET Standard 2.0
NuGet\Install-Package LiteDb.Extensions.Caching -Version 2.2.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
dotnet add package LiteDb.Extensions.Caching --version 2.2.0
<PackageReference Include="LiteDb.Extensions.Caching" Version="2.2.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LiteDb.Extensions.Caching --version 2.2.0
#r "nuget: LiteDb.Extensions.Caching, 2.2.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install LiteDb.Extensions.Caching as a Cake Addin
#addin nuget:?package=LiteDb.Extensions.Caching&version=2.2.0

// Install LiteDb.Extensions.Caching as a Cake Tool
#tool nuget:?package=LiteDb.Extensions.Caching&version=2.2.0

LiteDb.Extensions.Caching Nuget Quality Gate Status Coverage

An IDistributedCache implementation for LiteDB.

Usage

Registering the cache:


IServiceCollection services = //...

services.AddLiteDbCache("MyCache.db")
// or
services.AddLiteDbCache("MyCache.db", "MySuperStrongPassword1111!!!")
// or
services.AddLiteDbCache(options =>
{
    options.CachePath = "MyCache.db";
    options.Password = "MySuperStrongPassword1111!!!";
});

After this the IDistributedCache can be used as usual;

Fine controls

The package also allows you to have some manual controls for managing the cache through the ILiteDbCache interface:

public interface ILiteDbCache : IDistributedCache
{
    int CacheItemCount();
    Task<int> CacheCountAsync(CancellationToken cancellationToken = default);

    void Clear();
    Task ClearAsync(CancellationToken cancellationToke = default);

    ulong CacheSizeInBytes();
    Task<ulong> CacheSizeInBytesAsync();
}

Multi level cache

The library also adds a multi level cache implementation through the IMultiLevelCache interface, which first tries to retrieve an object from the IMemoryCache, then from the IDistributedCache. For serialization it uses System.Text.Json. Another string-based serializer can be used by implementing the IMultiLevelCacheSerializer interface and then registering it through DI.

var key = Guid.NewGuid().ToString();
var value = new TestData(Guid.NewGuid().ToString());

var storedValue = await MultiLevelCache.GetOrSetAsync(key, (_) => Task.FromResult(value), new MemoryCacheEntryOptions(), new DistributedCacheEntryOptions());

Contributing

Issues and pull requests are welcome.

If you find a bug, please try to recreate it with a test case in the test project and put it in the newly created issue (not mandatory)

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows
.NET Core netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard2.0 netstandard2.1
.NET Framework net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.2.0 90 9/8/2022
2.1.0 174 8/2/2022
2.0.0 154 8/1/2022
1.2.1 209 7/10/2022
1.2.0 185 7/9/2022
1.1.0 196 6/28/2022
1.0.3 197 6/28/2022
1.0.2 196 6/28/2022
1.0.1 193 6/28/2022
1.0.0 201 6/28/2022