An SQLite-backed cache implementation for .net projects for caching.
License
—
Deps
28
Install Size
—
Vulns
✓ 0
Published
Jul 18, 2023
$ dotnet add package EonaCat.Cache.SqliteEonaCat Sqlite cache for .Net projects.
var cache = new SqliteCache(options =>
{
options.Location = @"cache.db";
});
services.AddEonaCatSqliteCache(options => {
options.Location = @"cache.db";
});
Create your class to help with the caching serialization
using EonaCat.Cache.Sqlite;
namespace SqliteCacheTester
{
public static class DnsCache
{
private static SqliteCache _cache;
static DnsCache()
{
Init();
}
public static void Init()
{
_cache = new SqliteCache();
}
public static T? GetCacheAsync<T>(string cacheKey)
{
var cached = _cache.HasKey(cacheKey) ? _cache.Get<T>($"{cacheKey}") : default;
return cached;
}
public static void SetCache<T>(string cacheKey,
T cachedObject)
{
_cache.Set(cacheKey, cachedObject);
}
}
}
Get/Set
FooBar myFooBarObject = new FooBar();
DnsCache.SetCache("MY_KEY", myFooBarObject);
var fooBar = DnsCache.GetCacheAsync<FooBar>("MY_KEY");