You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.5 KiB
C#
49 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Enyim.Caching;
|
|
using Expedience.Infrastructure.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Expedience.Infrastructure
|
|
{
|
|
public interface IRepository : IDisposable
|
|
{
|
|
Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken);
|
|
}
|
|
|
|
public class ExpedienceRepository : IRepository
|
|
{
|
|
private readonly ExpedienceContext _dbContext;
|
|
private readonly IMemcachedClient _memcachedClient;
|
|
|
|
public ExpedienceRepository(ExpedienceContext dbContext, IMemcachedClient memcachedClient)
|
|
{
|
|
_dbContext = dbContext;
|
|
_memcachedClient = memcachedClient;
|
|
}
|
|
|
|
public async Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken)
|
|
{
|
|
var cacheKey = $"xpd-dcr-{expac}";
|
|
if (_memcachedClient.TryGet<List<DutyCompletionRecord>>(cacheKey, out var cachedValue))
|
|
{
|
|
return cachedValue;
|
|
}
|
|
else
|
|
{
|
|
var records = await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"CALL get_dutycompletionrecords {expac}")
|
|
.ToListAsync();
|
|
|
|
await _memcachedClient.AddAsync(cacheKey, records, TimeSpan.FromMinutes(10));
|
|
|
|
return records;
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_dbContext.Dispose();
|
|
}
|
|
}
|
|
}
|