예제 #1
0
        public void Invalidate()
        {
            var cacheKey   = _cacheKey.Key(_componentType, this);
            var deleteArgs = new EventInformation(cacheKey, _componentType.ConfiguredType, null, null);

            _cache.Delete(deleteArgs);
        }
예제 #2
0
        private object interceptUsingCache(MethodInfo method, object[] arguments)
        {
            var key = _cacheKey.Key(_configurationForType.ComponentType, _cachingComponent, method, arguments);
            var eventInformation = new EventInformation(key, _configurationForType.ComponentType.ConfiguredType, method, arguments);

            if (key == null)
            {
                return(callOriginalMethod(method, arguments));
            }
            var cachedValue = _cache.Get(eventInformation);

            if (cachedValue != null)
            {
                return(cachedValue);
            }
            var lockObject = _lockObjectGenerator.GetFor(key);

            if (lockObject == null)
            {
                return(executeAndPutInCache(method, arguments, eventInformation));
            }
            lock (lockObject)
            {
                var cachedValue2 = _cache.Get(eventInformation);
                return(cachedValue2 ?? executeAndPutInCache(method, arguments, eventInformation));
            }
        }
예제 #3
0
        public void Intercept(IInvocation invocation)
        {
            if (!_configurationForType.EnabledCache)
            {
                invocation.Proceed();
                return;
            }

            var method = invocation.Method;

            //ugly hack
            if (method.IsGenericMethod && !_configurationForType.CachedMethods.Contains(method, MethodInfoComparer.Instance))
            {
                invocation.Proceed();
                return;
            }
            var proxy     = (ICachingComponent)invocation.Proxy;
            var arguments = invocation.Arguments;

            var key = _cacheKey.Key(_configurationForType.ComponentType, proxy, method, arguments);

            if (key == null)
            {
                invocation.Proceed();
            }
            else
            {
                var eventInfo = new EventInformation(key, _configurationForType.ComponentType.ConfiguredType, invocation.Method, invocation.Arguments);
                if (tryGetValueFromCache(invocation, eventInfo))
                {
                    return;
                }

                var lockObject = _lockObjectGenerator.GetFor(key);
                if (lockObject == null)
                {
                    executeAndPutInCache(invocation, eventInfo);
                }
                else
                {
                    lock (lockObject)
                    {
                        if (tryGetValueFromCache(invocation, eventInfo))
                        {
                            return;
                        }
                        executeAndPutInCache(invocation, eventInfo);
                    }
                }
            }
        }