MeasureService use new cache model.

This commit is contained in:
ngfrolov 2022-06-10 17:33:08 +05:00
parent 9880caaf31
commit 62809a76cf

View File

@ -2,7 +2,7 @@
using AsbCloudApp.Exceptions;
using AsbCloudApp.Services;
using AsbCloudDb.Model;
using AsbCloudInfrastructure.Services.Cache;
using AsbCloudInfrastructure.EfCache;
using Mapster;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
@ -16,18 +16,17 @@ namespace AsbCloudInfrastructure.Services
{
private readonly IAsbCloudDbContext db;
private readonly IWellService wellService;
private readonly CacheTable<MeasureCategory> cacheCategories;
private static readonly System.TimeSpan cacheObsolescence = System.TimeSpan.FromMinutes(15);
public MeasureService(IAsbCloudDbContext db, Cache.CacheDb cacheDb, IWellService wellService)
public MeasureService(IAsbCloudDbContext db, IWellService wellService)
{
this.db = db;
this.wellService = wellService;
cacheCategories = cacheDb.GetCachedTable<MeasureCategory>((DbContext)db);
}
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
{
var entities = await cacheCategories.WhereAsync(token).ConfigureAwait(false);
var entities = await db.MeasureCategories.FromCacheAsync("MeasureCategories", cacheObsolescence, token).ConfigureAwait(false);
var dto = entities.ToDictionary(e => e.Id, e => e.Name);
return dto;
}