Esempio n. 1
0
        public void FillCache(CachedAttribute attribute, IInvocation invocation)
        {
            var cacheKeyGenerator = _cacheKeyGenerators.FirstOrDefault(c => c.GetType() == attribute.CacheKeyGenerator) ?? new DefaultCacheKeyGenerator();
            var cacheKey          = cacheKeyGenerator.GenerateCacheKey(invocation.Method, invocation.Arguments);

            if (_cache.Contains(cacheKey, attribute.CacheRegion))
            {
                invocation.ReturnValue = _cache.Get(cacheKey, attribute.CacheRegion);
            }
            else
            {
                invocation.Proceed();
                var expiration = attribute.TimeoutInMinutes == 0 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.AddMinutes(attribute.TimeoutInMinutes);
                _cache.Add(cacheKey, invocation.ReturnValue, expiration, attribute.CacheRegion);
            }
        }
Esempio n. 2
0
        public void FillCache(CachedAttribute attribute, IInvocation invocation)
        {
            var cacheKeyGenerator = _cacheKeyGenerators.FirstOrDefault(c => c.GetType() == attribute.CacheKeyGenerator) ?? new DefaultCacheKeyGenerator();
            var cacheKey = cacheKeyGenerator.GenerateCacheKey(invocation.Method, invocation.Arguments);

            if (_cache.Contains(cacheKey, attribute.CacheRegion))
            {
                invocation.ReturnValue = _cache.Get(cacheKey, attribute.CacheRegion);
            }
            else
            {
                invocation.Proceed();
                var expiration = attribute.TimeoutInMinutes == 0 ? DateTimeOffset.MaxValue : DateTimeOffset.Now.AddMinutes(attribute.TimeoutInMinutes);
                _cache.Add(cacheKey, invocation.ReturnValue, expiration, attribute.CacheRegion);
            }
        }