/// <summary> /// Gets an EF query and returns its hashed key to store in the cache. /// </summary> /// <param name="command">The EF query.</param> /// <param name="context">DbContext is a combination of the Unit Of Work and Repository patterns.</param> /// <param name="cachePolicy">determines the Expiration time of the cache.</param> /// <returns>Information of the computed key of the input LINQ query.</returns> public EFCacheKey GetEFCacheKey(DbCommand command, DbContext context, EFCachePolicy cachePolicy) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (cachePolicy == null) { throw new ArgumentNullException(nameof(cachePolicy)); } var cacheKey = getCacheKey(command, cachePolicy.CacheSaltKey); var cacheKeyHash = !string.IsNullOrEmpty(_cacheSettings.CacheKeyPrefix) ? $"{_cacheSettings.CacheKeyPrefix}{XxHashUnsafe.ComputeHash(cacheKey):X}" : $"{XxHashUnsafe.ComputeHash(cacheKey):X}"; var cacheDependencies = _cacheDependenciesProcessor.GetCacheDependencies(command, context, cachePolicy); _logger.LogDebug($"KeyHash: {cacheKeyHash}, CacheDependencies: {string.Join(", ", cacheDependencies)}."); return(new EFCacheKey(cacheDependencies) { KeyHash = cacheKeyHash }); }
/// <summary> /// Gets an EF query and returns its hashed key to store in the cache. /// </summary> /// <param name="command">The EF query.</param> /// <param name="context">DbContext is a combination of the Unit Of Work and Repository patterns.</param> /// <param name="cachePolicy">determines the Expiration time of the cache.</param> /// <returns>Information of the computed key of the input LINQ query.</returns> public EFCacheKey GetEFCacheKey(DbCommand command, DbContext context, EFCachePolicy cachePolicy) { if (command == null) { throw new ArgumentNullException(nameof(command)); } if (cachePolicy == null) { throw new ArgumentNullException(nameof(cachePolicy)); } //put the prefix in both places so the namespace will apply regardless of which key is used for access into the cache #pragma warning disable S125 // Sections of code should not be commented out string cacheKey = string.Empty; var cacheKeyHash = string.Empty; if (!string.IsNullOrEmpty(_keyPrefix)) { cacheKey += _keyPrefix; cacheKeyHash += _keyPrefix; } cacheKey += getCacheKey(command, cachePolicy.CacheSaltKey); cacheKeyHash += $"{XxHashUnsafe.ComputeHash(cacheKey):X}"; var cacheDependencies = _cacheDependenciesProcessor.GetCacheDependencies(command, context, cachePolicy); _logger.LogDebug($"KeyHash: {cacheKeyHash}, CacheDependencies: {string.Join(", ", cacheDependencies)}."); return(new EFCacheKey(cacheDependencies) { Key = cacheKey, KeyHash = cacheKeyHash }); }
/// <summary> /// Extracts the table names of an SQL command. /// </summary> public SortedSet <string> GetSqlCommandTableNames(string commandText) { var commandTextKey = $"{XxHashUnsafe.ComputeHash(commandText):X}"; return(_commandTableNames.GetOrAdd(commandTextKey, _ => new Lazy <SortedSet <string> >(() => getRawSqlCommandTableNames(commandText), LazyThreadSafetyMode.ExecutionAndPublication)).Value); }
/// <summary> /// Gets an EF query and returns its hashed key to store in the cache. /// </summary> /// <param name="command">The EF query.</param> /// <param name="context">DbContext is a combination of the Unit Of Work and Repository patterns.</param> /// <param name="cachePolicy">determines the Expiration time of the cache.</param> /// <returns>Information of the computed key of the input LINQ query.</returns> public EFCacheKey GetEFCacheKey(DbCommand command, DbContext context, EFCachePolicy cachePolicy) { var cacheKey = getCacheKey(command, cachePolicy.CacheSaltKey); var cacheKeyHash = $"{XxHashUnsafe.ComputeHash(cacheKey):X}"; var cacheDependencies = _cacheDependenciesProcessor.GetCacheDependencies(command, context, cachePolicy); _logger.LogDebug($"KeyHash: {cacheKeyHash}, CacheDependencies: {string.Join(", ", cacheDependencies)}."); return(new EFCacheKey { Key = cacheKey, KeyHash = cacheKeyHash, CacheDependencies = cacheDependencies }); }