31 lines
1004 B
C#
31 lines
1004 B
C#
|
using DD.Persistence.Models;
|
|||
|
using DD.Persistence.Repository.Repositories;
|
|||
|
using Microsoft.EntityFrameworkCore;
|
|||
|
using Microsoft.Extensions.Caching.Memory;
|
|||
|
|
|||
|
namespace DD.Persistence.Repository.RepositoriesCached;
|
|||
|
public class DataSchemeCachedRepository : DataSchemeRepository
|
|||
|
{
|
|||
|
private readonly IMemoryCache memoryCache;
|
|||
|
|
|||
|
public DataSchemeCachedRepository(DbContext db, IMemoryCache memoryCache) : base(db)
|
|||
|
{
|
|||
|
this.memoryCache = memoryCache;
|
|||
|
}
|
|||
|
|
|||
|
public override async Task Add(DataSchemeDto dataSourceSystemDto, CancellationToken token)
|
|||
|
{
|
|||
|
await base.Add(dataSourceSystemDto, token);
|
|||
|
|
|||
|
memoryCache.Set(dataSourceSystemDto.DiscriminatorId, dataSourceSystemDto);
|
|||
|
}
|
|||
|
|
|||
|
public override async Task<DataSchemeDto?> GetByDiscriminator(Guid discriminatorId, CancellationToken token)
|
|||
|
{
|
|||
|
var result = memoryCache.Get<DataSchemeDto>(discriminatorId)
|
|||
|
?? await base.GetByDiscriminator(discriminatorId, token);
|
|||
|
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|