/// <summary> /// This constructor is used when we wrap cached data in a CacheHandler so that /// we can reload the object after it has been removed from the cache. /// </summary> /// <param name="expirationTime"></param> /// <param name="storeOnlyForThisRequest"></param> /// <param name="input"></param> /// <param name="getNext"></param> /// <param name="cachedData"></param> public CacheHandler(IMethodInvocation input, GetNextHandlerDelegate getNext, object cachedData, TimeSpan expirationTime, string cacheManagerName = null) { this.keyGenerator = new DefaultCacheKeyGenerator(); if (input != null) { this.input = input; } if (getNext != null) { this.getNext = getNext; } if (cachedData != null) { this.cachedData = cachedData; } if (expirationTime != TimeSpan.Zero) { this.expirationTime = expirationTime; } this.cache = string.IsNullOrWhiteSpace(cacheManagerName) ? EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>() : EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>(cacheManagerName); }
public static void UpdateCache <T>(Object updatedValue, String methodName, Object[] input = null) { input = input != null ? input : new object[] { }; var method = typeof(T).GetMethod(methodName); var keyGenerator = new DefaultCacheKeyGenerator(); var cache = EnterpriseLibraryContainer.Current.GetInstance <ICacheManager>(); string cacheKey = keyGenerator.CreateCacheKey(method, input); if (updatedValue == null && cache.Contains(cacheKey)) { cache.Remove(cacheKey); } else { cache.Add(cacheKey, updatedValue); } }