Add user accounts base

This commit is contained in:
Kieran
2022-02-21 22:35:06 +00:00
parent 8629954ffe
commit 3bffcdeb13
33 changed files with 574 additions and 166 deletions

View File

@@ -0,0 +1,46 @@
using Microsoft.Extensions.Caching.Memory;
using VoidCat.Services.Abstractions;
namespace VoidCat.Services.InMemory;
public class InMemoryCache : ICache
{
private readonly IMemoryCache _cache;
public InMemoryCache(IMemoryCache cache)
{
_cache = cache;
}
public ValueTask<T?> Get<T>(string key)
{
return ValueTask.FromResult(_cache.Get<T?>(key));
}
public ValueTask Set<T>(string key, T value, TimeSpan? expire = null)
{
if (expire.HasValue)
{
_cache.Set(key, value, expire.Value);
}
else
{
_cache.Set(key, value);
}
return ValueTask.CompletedTask;
}
public ValueTask<string[]> GetList(string key)
{
return ValueTask.FromResult(_cache.Get<string[]>(key));
}
public ValueTask AddToList(string key, string value)
{
var list = new HashSet<string>(GetList(key).Result);
list.Add(value);
_cache.Set(key, list.ToArray());
return ValueTask.CompletedTask;
}
}

View File

@@ -1,38 +0,0 @@
using Microsoft.Extensions.Caching.Memory;
using VoidCat.Model.Paywall;
using VoidCat.Services.Abstractions;
namespace VoidCat.Services.InMemory;
public class InMemoryPaywallStore : IPaywallStore
{
private readonly IMemoryCache _cache;
public InMemoryPaywallStore(IMemoryCache cache)
{
_cache = cache;
}
public ValueTask<PaywallConfig?> GetConfig(Guid id)
{
return ValueTask.FromResult(_cache.Get(id) as PaywallConfig);
}
public ValueTask SetConfig(Guid id, PaywallConfig config)
{
_cache.Set(id, config);
return ValueTask.CompletedTask;
}
public ValueTask<PaywallOrder?> GetOrder(Guid id)
{
return ValueTask.FromResult(_cache.Get(id) as PaywallOrder);
}
public ValueTask SaveOrder(PaywallOrder order)
{
_cache.Set(order.Id, order,
order.Status == PaywallOrderStatus.Paid ? TimeSpan.FromDays(1) : TimeSpan.FromSeconds(5));
return ValueTask.CompletedTask;
}
}

View File

@@ -1,4 +1,5 @@
using Microsoft.Extensions.Caching.Memory;
using VoidCat.Model;
using VoidCat.Services.Abstractions;
namespace VoidCat.Services.InMemory;