コード例 #1
0
ファイル: DictionaryCacheKey.cs プロジェクト: drdk/sleipner
        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());
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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()));
        }