Update spam circle cache after updating circle status.

This commit is contained in:
2025-09-11 00:26:11 -04:00
parent 3c0a39b324
commit 39274165cb
10 changed files with 70 additions and 37 deletions

View File

@@ -0,0 +1,27 @@
using JSMR.Application.Common.Caching;
using JSMR.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace JSMR.Infrastructure.Caching;
public abstract class CacheObject<T>(ICache cache) : ICacheObject<T>
{
protected abstract string Key { get; }
protected abstract Task<T> FetchAsync(CancellationToken cancellationToken = default);
protected virtual CacheEntryOptions Options => new() { SlidingExpiration = TimeSpan.FromHours(1) };
public async virtual Task<T> GetAsync(CancellationToken cancellationToken = default)
{
return await cache.GetAsync<T>(Key, cancellationToken) ?? await RefreshAsync(cancellationToken);
}
public async virtual Task<T> RefreshAsync(CancellationToken cancellationToken = default)
{
T cacheObject = await FetchAsync(cancellationToken);
await cache.SetAsync(Key, cacheObject, Options, cancellationToken);
return cacheObject;
}
}