public bool Equals(DictionaryCacheKey other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other._primaryKey, _primaryKey) && _cacheKeys.SequenceEqual(other._cacheKeys, new CollectionComparer()); }
public CachedObject <TResult> GetItem <TResult>(ProxyRequest <T, TResult> proxyRequest, CachePolicy cachePolicy) { var cacheKey = new DictionaryCacheKey(proxyRequest.Method, proxyRequest.Parameters); if (_cache.ContainsKey(cacheKey)) { var cachedObject = _cache[cacheKey]; if (cachedObject.ThrownException != null && cachedObject.Created.AddSeconds(cachePolicy.ExceptionCacheDuration) > DateTime.Now) { return(new CachedObject <TResult>(CachedObjectState.Exception, cachedObject.ThrownException)); } else if (cachedObject.ThrownException != null) { return(new CachedObject <TResult>(CachedObjectState.None, null)); } if (cachedObject.AbsoluteDuration.TotalSeconds > 0 && cachedObject.Created + cachedObject.AbsoluteDuration < DateTime.Now) { return(new CachedObject <TResult>(CachedObjectState.None, null)); } return(new CachedObject <TResult>(cachedObject.IsExpired ? CachedObjectState.Stale : CachedObjectState.Fresh, (TResult)cachedObject.Object)); } return(new CachedObject <TResult>(CachedObjectState.None, null)); }
public void StoreException <TResult>(ProxyRequest <T, TResult> proxyRequest, CachePolicy cachePolicy, Exception exception) { var cacheKey = new DictionaryCacheKey(proxyRequest.Method, proxyRequest.Parameters); var duration = TimeSpan.FromSeconds(cachePolicy.CacheDuration); var absoluteDuration = TimeSpan.FromSeconds(cachePolicy.MaxAge); _cache[cacheKey] = new DictionaryCachedItem(exception, duration, absoluteDuration); }
public void Purge <TResult>(Expression <Func <T, TResult> > expression) { var methodInfo = SymbolExtensions.GetMethodInfo(expression); var parameters = SymbolExtensions.GetParameter(expression); var proxyExpression = new ProxyRequest <T, TResult>(methodInfo, parameters); var cacheKey = new DictionaryCacheKey(proxyExpression.Method, proxyExpression.Parameters); _cache.Remove(cacheKey); }
public bool TryGetRaw <TResult>(ProxyRequest <T, TResult> proxyRequest, out object result) { var cacheKey = new DictionaryCacheKey(proxyRequest.Method, proxyRequest.Parameters); if (_cache.ContainsKey(cacheKey)) { result = _cache[cacheKey]; return(true); } result = null; return(false); }
public bool Equals(DictionaryCacheKey other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other._primaryKey, _primaryKey) && _cacheKeys.SequenceEqual(other._cacheKeys, new CollectionComparer())); }