@@ -284,11 +284,26 @@ private async Task HandleSpecificDomainEvent(MerchantFeeSettledEvent domainEvent
284284 }
285285
286286 private async Task < List < TransactionFeeToCalculate > > GetTransactionFeesForCalculation ( TransactionAggregate transactionAggregate , CancellationToken cancellationToken ) {
287+ Boolean contractProductFeeCacheEnabled ;
288+ String contractProductFeeCacheEnabledValue = ConfigurationReader . GetValue ( "ContractProductFeeCacheEnabled" ) ;
289+ if ( String . IsNullOrEmpty ( contractProductFeeCacheEnabledValue ) ) {
290+ contractProductFeeCacheEnabled = false ;
291+ }
292+ else {
293+ contractProductFeeCacheEnabled = Boolean . Parse ( contractProductFeeCacheEnabledValue ) ;
294+ }
287295
288- // Ok we should have filtered out the not applicable transactions
289- // Check if we have fees for this product in the cache
290- Boolean feesInCache = this . MemoryCache . TryGetValue ( ( transactionAggregate . EstateId , transactionAggregate . ContractId , transactionAggregate . ProductId ) ,
291- out List < ContractProductTransactionFee > feesForProduct ) ;
296+ Boolean feesInCache ;
297+ List < ContractProductTransactionFee > feesForProduct = null ;
298+ if ( contractProductFeeCacheEnabled == false ) {
299+ feesInCache = false ;
300+ }
301+ else {
302+ // Ok we should have filtered out the not applicable transactions
303+ // Check if we have fees for this product in the cache
304+ feesInCache = this . MemoryCache . TryGetValue ( ( transactionAggregate . EstateId , transactionAggregate . ContractId , transactionAggregate . ProductId ) ,
305+ out feesForProduct ) ;
306+ }
292307
293308 if ( feesInCache == false ) {
294309 Logger . LogInformation ( $ "Fees for Key: Estate Id { transactionAggregate . EstateId } Contract Id { transactionAggregate . ContractId } ProductId { transactionAggregate . ProductId } not found in the cache") ;
@@ -301,18 +316,21 @@ private async Task<List<TransactionFeeToCalculate>> GetTransactionFeesForCalcula
301316 transactionAggregate . ContractId ,
302317 transactionAggregate . ProductId ,
303318 cancellationToken ) ;
304- // Now add this the result to the cache
305- String contractProductFeeCacheExpiryInHours = ConfigurationReader . GetValue ( "ContractProductFeeCacheExpiryInHours" ) ;
306- if ( String . IsNullOrEmpty ( contractProductFeeCacheExpiryInHours ) ) {
307- contractProductFeeCacheExpiryInHours = "168" ; // 7 Days default
308- }
309- this . MemoryCache . Set ( ( transactionAggregate . EstateId , transactionAggregate . ContractId , transactionAggregate . ProductId ) ,
310- feesForProduct ,
311- new MemoryCacheEntryOptions ( ) {
312- AbsoluteExpirationRelativeToNow = TimeSpan . FromHours ( Int32 . Parse ( contractProductFeeCacheExpiryInHours ) )
313- } ) ;
314- Logger . LogInformation ( $ "Fees for Key: Estate Id { transactionAggregate . EstateId } Contract Id { transactionAggregate . ContractId } ProductId { transactionAggregate . ProductId } added to cache") ;
315319
320+ if ( contractProductFeeCacheEnabled == true ) {
321+ // Now add this the result to the cache
322+ String contractProductFeeCacheExpiryInHours = ConfigurationReader . GetValue ( "ContractProductFeeCacheExpiryInHours" ) ;
323+ if ( String . IsNullOrEmpty ( contractProductFeeCacheExpiryInHours ) ) {
324+ contractProductFeeCacheExpiryInHours = "168" ; // 7 Days default
325+ }
326+
327+ this . MemoryCache . Set ( ( transactionAggregate . EstateId , transactionAggregate . ContractId , transactionAggregate . ProductId ) ,
328+ feesForProduct ,
329+ new MemoryCacheEntryOptions ( ) {
330+ AbsoluteExpirationRelativeToNow = TimeSpan . FromHours ( Int32 . Parse ( contractProductFeeCacheExpiryInHours ) )
331+ } ) ;
332+ Logger . LogInformation ( $ "Fees for Key: Estate Id { transactionAggregate . EstateId } Contract Id { transactionAggregate . ContractId } ProductId { transactionAggregate . ProductId } added to cache") ;
333+ }
316334 }
317335 else
318336 {
0 commit comments