diff --git a/src/Spd.Resource.Repository/LicenceFee/LicenceFeeRepository.cs b/src/Spd.Resource.Repository/LicenceFee/LicenceFeeRepository.cs index 380f6089f..19d070be8 100644 --- a/src/Spd.Resource.Repository/LicenceFee/LicenceFeeRepository.cs +++ b/src/Spd.Resource.Repository/LicenceFee/LicenceFeeRepository.cs @@ -1,4 +1,5 @@ using AutoMapper; +using Microsoft.Dynamics.CRM; using Microsoft.Extensions.Caching.Distributed; using Spd.Utilities.Dynamics; @@ -10,11 +11,18 @@ internal class LicenceFeeRepository(IDynamicsContextFactory contextFactory, IMap public async Task QueryAsync(LicenceFeeQry qry, CancellationToken cancellationToken) { - var feeResult = await cache.GetAsync( - "license-fees", - async ct => await context.spd_licencefees.Expand(a => a.spd_ServiceTypeId).GetAllPagesAsync(ct), - TimeSpan.FromMinutes(60), - cancellationToken) ?? []; + IEnumerable? feeResult = await cache.GetAsync>("spd_licencefee", cancellationToken); + if (feeResult == null) + { + feeResult = context.spd_licencefees.Expand(a => a.spd_ServiceTypeId).ToList(); + await cache.SetAsync>("spd_licencefee", feeResult, new TimeSpan(1, 0, 0)); + } + //Yossi, please check why this failed. + //var feeResult = await cache.GetAsync( + // "license-fees", + // async ct => await context.spd_licencefees.Expand(a => a.spd_ServiceTypeId).GetAllPagesAsync(ct), + // TimeSpan.FromMinutes(60), + // cancellationToken) ?? []; if (!qry.IncludeInactive) feeResult = feeResult.Where(d => d.statecode != DynamicsConstants.StateCode_Inactive); @@ -51,7 +59,7 @@ public async Task QueryAsync(LicenceFeeQry qry, Cancellation return new LicenceFeeListResp { - LicenceFees = mapper.Map>(feeResult) + LicenceFees = mapper.Map>(feeResult.ToList()) }; } } \ No newline at end of file