LightningDbCache 0.14.1
dotnet add package LightningDbCache --version 0.14.1
NuGet\Install-Package LightningDbCache -Version 0.14.1
<PackageReference Include="LightningDbCache" Version="0.14.1" />
paket add LightningDbCache --version 0.14.1
#r "nuget: LightningDbCache, 0.14.1"
// 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
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 | Versions 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. |
-
.NETStandard 2.0
- LightningDb (>= 0.16.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
-
net6.0
- LightningDb (>= 0.16.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
-
net7.0
- LightningDb (>= 0.16.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
-
net8.0
- LightningDb (>= 0.16.0)
- Microsoft.Extensions.Caching.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
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 | 102 | 4/26/2024 |