forked from ddrilling/AsbCloudServer
MeasureService use new cache model.
This commit is contained in:
parent
9880caaf31
commit
62809a76cf
@ -2,7 +2,7 @@
|
|||||||
using AsbCloudApp.Exceptions;
|
using AsbCloudApp.Exceptions;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
using AsbCloudInfrastructure.Services.Cache;
|
using AsbCloudInfrastructure.EfCache;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -16,18 +16,17 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IWellService wellService;
|
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.db = db;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
cacheCategories = cacheDb.GetCachedTable<MeasureCategory>((DbContext)db);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Dictionary<int, string>> GetCategoriesAsync(CancellationToken token)
|
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);
|
var dto = entities.ToDictionary(e => e.Id, e => e.Name);
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user