LightningDbCache 0.14.1

dotnet add package LightningDbCache --version 0.14.1
NuGet\Install-Package LightningDbCache -Version 0.14.1
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.
<PackageReference Include="LightningDbCache" Version="0.14.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LightningDbCache --version 0.14.1
#r "nuget: LightningDbCache, 0.14.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install LightningDbCache as a Cake Addin
#addin nuget:?package=LightningDbCache&version=0.14.1

// Install LightningDbCache as a Cake Tool
#tool nuget:?package=LightningDbCache&version=0.14.1

LightningDbCache

build Coverage Status

LightningDbCache is an implementation of IDistributedCache that uses LightningDb as a backing store. LightningDb is a fast, transactional, memory-mapped, key-value store with a very small footprint. LightningDbCache is made possible by leveraging the Lightning.NET library to facilitate the interplay with LightningDb itself.

Getting Started

Installation

Add a reference to the LightningDbCache package to your project

dotnet add package LightningDbCache

Basic Usage

// Register the cache in the DI container
services.AddLightningDbCache();

NOTE: This registers a singleton instance implementation of IDistributedCache.

// Inject the cache into your class
public class MyService
{
    private readonly IDistributedCache _cache;

    public MyService(IDistributedCache cache)
    {
        _cache = cache;
    }

    public async Task DoSomethingAsync()
    {
        // Store a value in the cache
        await _cache.SetStringAsync("myKey", "myValue");

        // Retrieve a value from the cache
        var value = await _cache.GetStringAsync("myKey");
    }
}

Configuration

The following configuration options are supported:

Option Datatype Description Default Value
DataPath string The directory where the cache database files will be stored. Directory.GetCurrentDirectory()
MaxSize long The maximum size of the cache database in bytes. 209715200 (200MB)
ExpirationScanFrequency Timespan The frequency at which the cache will be scanned for expired items. TimeSpan.FromMinutes(1)

Examples

Configure the cache from appsettings.json
{
  "LightningDbCache": {
    "DataPath": "C:\\data\\mycache",
    "MaxSize": 100000000,
    "ExpirationScanFrequency": "00:00:30"
  }
}
services.AddLightningDbCache();
Configure the cache from appsettings.json with custom section name
{
  "MyCache": {
    "DataPath": "/data/mycache",
    "MaxSize": 100000000,
    "ExpirationScanFrequency": "00:00:30"
  }
}
services.AddLightningDbCache("MyCache");
// or
services.AddLightningDbCache(configuration.GetSection("MyCache"));
Configure the cache from code
services.AddLightningDbCache(options =>
{
    options.DataPath = "C:\\data\\mycache";
    options.MaxSize = 100000000;
    options.ExpirationScanFrequency = TimeSpan.FromSeconds(30);
});

Notes

Expiration

This library fully implements IDistributedCache expiration options. While expired items will never be returned from the cache, they will not be removed from the backing store until the next time the cache is scanned for expired items. This is done to avoid the overhead of removing items from the backing store on every cache access.

Database Size

The database file(s) on disk will grow up-to the MaxSize value. If the database size reaches the MaxSize value, new items will not be added to the cache until enough items are removed to bring the database size below the MaxSize value.

Multithreading and Multiple Processes

Public members of LightningDbCache are thread-safe.

While it is possible, care should be taken when sharing a cache database between multiple processes. Some filesystems may not support memory-mapped files in a way that is compatible with LightningDb. For more in-depth reading on LightningDb's threading and multiple process support, see the LightningDb Docs

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
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
0.14.1 77 4/26/2024