31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			31 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Core.Cerberos.Infraestructure.Caching.Configs;
 | |
| 
 | |
| namespace LSA.Core.Dapper.Service.Caching
 | |
| {
 | |
|     public static class CacheHelper
 | |
|     {
 | |
|         /// <summary>
 | |
|         /// Determines the cache duration based on specific duration, settings, or a default value.
 | |
|         /// </summary>
 | |
|         /// <param name="specificCacheDuration">Specific cache duration in minutes, if provided.</param>
 | |
|         /// <param name="cacheSettings">General cache settings containing default duration values.</param>
 | |
|         /// <returns>The cache duration as a TimeSpan.</returns>
 | |
|         public static TimeSpan GetCacheDuration(CacheSettings cacheSettings, int? specificCacheDuration = 0)
 | |
|         {
 | |
|             var defaultCacheDuration = TimeSpan.FromMinutes(.5);
 | |
| 
 | |
|             if (specificCacheDuration.HasValue && specificCacheDuration.Value > 0)
 | |
|             {
 | |
|                 return TimeSpan.FromMinutes(specificCacheDuration.Value);
 | |
|             }
 | |
| 
 | |
|             if (cacheSettings.DefaultCacheDurationInMinutes > 0)
 | |
|             {
 | |
|                 return TimeSpan.FromMinutes(cacheSettings.DefaultCacheDurationInMinutes);
 | |
|             }
 | |
| 
 | |
|             return defaultCacheDuration;
 | |
|         }
 | |
|     }
 | |
| }
 | 
