diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs index 3b1ef55a..f1ae1144 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationService.cs @@ -1,9 +1,9 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; -using AsbCloudInfrastructure.Services.Cache; using Mapster; using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Caching.Memory; using System; using System.Collections.Generic; using System.Linq; @@ -16,9 +16,8 @@ namespace AsbCloudInfrastructure.Services.WellOperationService public class WellOperationService : IWellOperationService { private readonly IAsbCloudDbContext db; + private readonly IMemoryCache memoryCache; private readonly IWellService wellService; - private readonly CacheTable cachedOperationCategories; - private readonly CacheTable cachedSectionTypes; private Dictionary? firstOperationsCache = null; @@ -33,22 +32,25 @@ namespace AsbCloudInfrastructure.Services.WellOperationService public const int idOperationTypeFact = 1; public const int idOperationTypeRepair = 1031; - public WellOperationService(IAsbCloudDbContext db, CacheDb cache, IWellService wellService) + public WellOperationService(IAsbCloudDbContext db, IMemoryCache memoryCache, IWellService wellService) { this.db = db; + this.memoryCache = memoryCache; this.wellService = wellService; - cachedOperationCategories = cache.GetCachedTable((DbContext)db); - cachedSectionTypes = cache.GetCachedTable((DbContext)db); } public IDictionary GetSectionTypes() - => cachedSectionTypes.ToDictionary(s => s.Id, s => s.Caption); + => memoryCache + .GetOrCreateBasic(db) + .ToDictionary(s => s.Id, s => s.Caption); public IEnumerable GetCategories() { - var operationTypes = cachedOperationCategories - .Distinct().OrderBy(o => o.Name); - var result = operationTypes.Adapt>(); + var operationCategories = memoryCache + .GetOrCreateBasic(db) + .Distinct() + .OrderBy(o => o.Name); + var result = operationCategories.Adapt>(); return result; } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 7869d534..f4dc40de 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -37,13 +37,13 @@ namespace AsbCloudInfrastructure.Services .Include(w => w.RelationCompaniesWells) .ThenInclude(r => r.Company); - public WellService(IAsbCloudDbContext db, IMemoryCache memoryCache, CacheDb cacheDb, ITelemetryService telemetryService, ITimezoneService timezoneService) + public WellService(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService, ITimezoneService timezoneService) : base(db, memoryCache, MakeQueryWell) { this.telemetryService = telemetryService; this.timezoneService = timezoneService; - this.wellOperationService = new WellOperationService.WellOperationService(db, cacheDb, this); + this.wellOperationService = new WellOperationService.WellOperationService(db, memoryCache, this); companyTypesService = new CrudCacheServiceBase(dbContext, memoryCache); }