reeplace cerberos by talos
This commit is contained in:
		
							
								
								
									
										47
									
								
								Core.Thalos.Infraestructure/Caching/CacheKeyHelper.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								Core.Thalos.Infraestructure/Caching/CacheKeyHelper.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| using System.Reflection; | ||||
| using System.Text; | ||||
| using System.Text.RegularExpressions; | ||||
|  | ||||
| namespace LSA.Core.Dapper.Service.Caching | ||||
| { | ||||
|     public static class CacheKeyHelper | ||||
|     { | ||||
|         public static string GenerateCacheKey(object instance, string methodName, params object[] parameters) | ||||
|         { | ||||
|             var className = instance.GetType().Name; | ||||
|             var keyBuilder = new StringBuilder($"{className}.{methodName}"); | ||||
|  | ||||
|             foreach (var param in parameters) | ||||
|             { | ||||
|                 string normalizedParam = NormalizeParameter(param); | ||||
|                 keyBuilder.Append($".{normalizedParam}"); | ||||
|             } | ||||
|  | ||||
|             return keyBuilder.ToString(); | ||||
|         } | ||||
|  | ||||
|         private static string NormalizeParameter(object param) | ||||
|         { | ||||
|             if (param == null) | ||||
|             { | ||||
|                 return "null"; | ||||
|             } | ||||
|  | ||||
|             string paramString; | ||||
|  | ||||
|             if (param is DateTime dateTime) | ||||
|             { | ||||
|                 paramString = dateTime.ToString("yyyyMMdd"); | ||||
|             } | ||||
|             else | ||||
|             { | ||||
|                 paramString = param.ToString(); | ||||
|             } | ||||
|  | ||||
|             // Replace special characters with an underscore | ||||
|             string normalizedParam = Regex.Replace(paramString, @"[^a-zA-Z0-9]", "_"); | ||||
|  | ||||
|             return normalizedParam; | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 Sergio Matias Urquin
					Sergio Matias Urquin