mirror of
https://git.v0l.io/Kieran/void.cat.git
synced 2025-04-16 13:01:03 +02:00
Co-authored-by: Kieran <kieran@harkin.me> Reviewed-on: https://git.v0l.io/Kieran/void.cat/pulls/65
39 lines
855 B
C#
39 lines
855 B
C#
using VoidCat.Services.Abstractions;
|
|
|
|
namespace VoidCat.Services;
|
|
|
|
/// <inheritdoc />
|
|
public abstract class BasicCacheStore<TStore> : IBasicStore<TStore>
|
|
{
|
|
protected readonly ICache Cache;
|
|
|
|
protected BasicCacheStore(ICache cache)
|
|
{
|
|
Cache = cache;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual ValueTask<TStore?> Get(Guid id)
|
|
{
|
|
return Cache.Get<TStore>(MapKey(id));
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual ValueTask Add(Guid id, TStore obj)
|
|
{
|
|
return Cache.Set(MapKey(id), obj);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public virtual ValueTask Delete(Guid id)
|
|
{
|
|
return Cache.Delete(MapKey(id));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Map an id to a key in the KV store
|
|
/// </summary>
|
|
/// <param name="id"></param>
|
|
/// <returns></returns>
|
|
protected abstract string MapKey(Guid id);
|
|
} |