CacheBox.LiteDb
1.0.3
dotnet add package CacheBox.LiteDb --version 1.0.3
NuGet\Install-Package CacheBox.LiteDb -Version 1.0.3
<PackageReference Include="CacheBox.LiteDb" Version="1.0.3" />
paket add CacheBox.LiteDb --version 1.0.3
#r "nuget: CacheBox.LiteDb, 1.0.3"
// Install CacheBox.LiteDb as a Cake Addin #addin nuget:?package=CacheBox.LiteDb&version=1.0.3 // Install CacheBox.LiteDb as a Cake Tool #tool nuget:?package=CacheBox.LiteDb&version=1.0.3
CacheBox
CacheBox is a lightweight and flexible caching solution designed for .NET applications. It provides an abstraction over multiple cache providers, allowing you to seamlessly switch between different caching providers while maintaining a consistent API.
Features
- Pluggable Cache Providers: Use multiple cache backends like in-memory, Redis, or distributed caches with ease.
- Dependency Injection Support: Integrate CacheBox seamlessly into your .NET Core projects using dependency injection.
- High Performance: Optimized for minimal overhead.
Installation
To install CacheBox in your project, you can use the following NuGet command for your provider:
dotnet add package CacheBox.LiteDb
dotnet add package CacheBox.Memory
dotnet add package CacheBox.Redis
dotnet add package CacheBox.Sqlite
Usage
Basic Setup
Configuration
CacheBox uses a very simple configuration for all providers with 3 lines.
"Cache": { // Optional: Global prefix to prepend to all keys. Useful for shared systems. "AppPrefix": "MyApplication", // Connection string to connect to the provider. See examples and links below for individual providers. "ConnectionString": "MyConnectionString", // Optional: Default TTL of the stored items. This is a string representation interpreted by TimeSpan.TryParse(). "Timeout": "0:10:0" },
See the Microsoft Documentation for examples of time strings.
Register CacheBox in your DI Container
using CacheBox; public class Startup { public void ConfigureServices(IServiceCollection services) { services.AddCacheProvider<MemoryCacheProvider>(); // Example using in-memory cache } }
Use CacheBox in your application
public class MyService { private readonly ICacheProvider _cache; public MyService(ICacheProvider cache) { _cache = cache; } public async Task DoWorkAsync() { string data = await _cache.GetAsync("myKey", nameof(MyService)); MyClass stronglyTyped = await _cache.GetAsync<MyClass>("myOtherKey", nameof(MyService)); } }
Switching Providers
To switch cache providers, simply register the desired provider in ConfigureServices
:
services.AddCacheProvider<RedisCacheProvider>();
Cache Providers
CacheBox supports multiple cache providers. Each provider can be installed as a separate NuGet package:
LiteDbCacheProvider: Uses LiteDb as the cache backing.
Example connection string:
Filename=D:\\cache.db;Password=MyPassword;Connection=shared
See here for documentation.
Note: You must use a shared connection for a distributed cache, otherwise the first service to connect will create a lock.
MemoryCacheProvider: A simple in-memory cache.
A connection string is not needed for in-memory caching.
RedisCacheProvider: Uses Redis as the cache backing.
Example connection string:
myRedisServer:6379,password=MyPassword
See here for documentation.
SqliteCacheProvider: Uses Sqlite as the cache backing.
Example connection string:
Data Source=Cache.db;Password=MyPassword
See here for documentation.
Adding Custom Providers
You can also implement your own custom cache provider by creating a class that implements the ICacheProvider
interface.
public class MyCustomCacheProvider : ICacheProvider
{
// Implementation goes here
}
License
CacheBox is licensed under the GPL License. See the LICENSE for more information.
Contributing
Contributions are always welcome! Feel free to open an issue or submit a pull request.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | 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 was computed. 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. |
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.