Refactor caching

main
ilitirit 3 years ago
parent b1bfa3dca5
commit b74fc46fe2

@ -25,19 +25,13 @@ namespace Expedience.Infrastructure
public async Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken) public async Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken)
{ {
var cacheKey = $"xpd-dcr-{expac}"; var cacheKey = $"xpd-dcr-{expac}";
if (_memcachedClient.TryGet<List<DutyCompletionRecord>>(cacheKey, out var cachedValue)) var cacheSeconds = 600;
{ var records = await _memcachedClient.GetValueOrCreateAsync(cacheKey, cacheSeconds,
return cachedValue; async () => await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"SELECT * FROM public.get_dutycompletionrecords({expac})")
} .ToListAsync());
else
{
var records = await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"SELECT * FROM public.get_dutycompletionrecords({expac})")
.ToListAsync();
await _memcachedClient.AddAsync(cacheKey, records, TimeSpan.FromMinutes(10));
return records; return records;
} }
}
public void Dispose() public void Dispose()
{ {

Loading…
Cancel
Save