https://github.com/newky2k/cachemanager
Managed .NET cache management framework for .NET Standard 2.0 and .NET 6 or .NET 8
https://github.com/newky2k/cachemanager
cache dotnet litedb netstandard
Last synced: about 1 month ago
JSON representation
Managed .NET cache management framework for .NET Standard 2.0 and .NET 6 or .NET 8
- Host: GitHub
- URL: https://github.com/newky2k/cachemanager
- Owner: newky2k
- License: mit
- Created: 2021-07-19T15:01:09.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-12-01T21:59:34.000Z (10 months ago)
- Last Synced: 2025-08-15T08:57:23.968Z (about 2 months ago)
- Topics: cache, dotnet, litedb, netstandard
- Language: C#
- Homepage:
- Size: 57.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DSoft.CacheManager
Managed .NET cache management framework for .NET Standard 2.0 and .NET 6 or .NET 8## Features
- Works on all platforms that support .NET Standard 2.0, .NET 6 or .NET 8
- Extendable to add different backends for storing the cached data
- LiteDb provider is available with more to come
- Designed to work with Microsoft's standard Dependency Injection mechanism
- Factory class is provided if you don't use DI
- async/await compatible## Usage
To use CacheManager you need to add packages `DSoft.CacheManager` and your preferred backend such as `DSoft.CacheManager.LiteDB`
### Dependency Injection
Call `RegisterCacheManager`, where `T` is the backend implementation, to register the cache manager
using DSoft.CacheManager;
using DSoft.CacheManager.LiteDB;private void ConfigureServices(IConfiguration configuration, IServiceCollection services)
{
services.RegisterCacheManager();
}### Consume
You can inject `ICacheManager` into your services or you can use `CacheManagerFactory.Create` to create an instance manually.
var cacheManager = ServiceHost.GetRequiredService();
var dataKey = typeof(SomeData).Name;
await cacheManager.LoadAsync(); // optionally pre-warm the cache
var items = new List()
{
new SomeData() { Id = 1, Name = "One", IsEnabled = true },
new SomeData() { Id = 2, Name = "Two", IsEnabled = false },
new SomeData() { Id = 3, Name = "Three", IsEnabled = true },
new SomeData() { Id = 4, Name = "Four", IsEnabled = false },
};var exists = cacheManager.IsKeyRegistered(dataKey);
if (exists)
{
var ogItems = cacheManager.GetItems(dataKey);var count = ogItems.Count;
}cacheManager.SetItems(dataKey, items);
var itemsOut = cacheManager.GetItems(dataKey);