Skip to content

Commit

Permalink
fix cache issue for licence fee (#1309)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

-fix cache issue for licence fee
  • Loading branch information
peggy-quartech authored Aug 17, 2024
1 parent 61d34bc commit e6e677f
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Spd.Resource.Repository/LicenceFee/LicenceFeeRepository.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using AutoMapper;
using Microsoft.Dynamics.CRM;
using Microsoft.Extensions.Caching.Distributed;
using Spd.Utilities.Dynamics;

Expand All @@ -10,11 +11,18 @@ internal class LicenceFeeRepository(IDynamicsContextFactory contextFactory, IMap

public async Task<LicenceFeeListResp> 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<spd_licencefee>? feeResult = await cache.GetAsync<IEnumerable<spd_licencefee>>("spd_licencefee", cancellationToken);
if (feeResult == null)
{
feeResult = context.spd_licencefees.Expand(a => a.spd_ServiceTypeId).ToList();
await cache.SetAsync<IEnumerable<spd_licencefee>>("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);
Expand Down Expand Up @@ -51,7 +59,7 @@ public async Task<LicenceFeeListResp> QueryAsync(LicenceFeeQry qry, Cancellation

return new LicenceFeeListResp
{
LicenceFees = mapper.Map<IEnumerable<LicenceFeeResp>>(feeResult)
LicenceFees = mapper.Map<IEnumerable<LicenceFeeResp>>(feeResult.ToList())
};
}
}

0 comments on commit e6e677f

Please sign in to comment.