Exemple #1
0
        private object interceptUsingCache(MethodInfo method, object[] arguments)
        {
            var keyAndItsDependingKeys = _configurationForType.CacheKey.GetAndPutKey(_configurationForType.ComponentType, _cachingComponent, method, arguments);

            return(keyAndItsDependingKeys.Key == null?
                   callOriginalMethod(method, arguments) :
                       _cache.GetAndPutIfNonExisting(keyAndItsDependingKeys, method, arguments, () => callOriginalMethod(method, arguments)));
        }
Exemple #2
0
        private object interceptUsingCache(MethodInfo method, object[] arguments)
        {
            var keyAndItsDependingKeys = _configurationForType.CacheKey.GetAndPutKey(_configurationForType.ComponentType, _cachingComponent, method, arguments);

            if (keyAndItsDependingKeys.Key == null)
            {
                return(callOriginalMethod(method, arguments));
            }

            var eventInformation = new EventInformation(keyAndItsDependingKeys.Key, _configurationForType.ComponentType.ConfiguredType, method, arguments);

            return(_cache.GetAndPutIfNonExisting(eventInformation, keyAndItsDependingKeys.DependingRemoveKeys, () => callOriginalMethod(method, arguments)));
        }
        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 keyAndItsDependingKeys = _configurationForType.CacheKey.GetAndPutKey(_configurationForType.ComponentType, proxy, method, arguments);

            if (keyAndItsDependingKeys.Key == null)
            {
                invocation.Proceed();
            }
            else
            {
                var eventInfo = new EventInformation(keyAndItsDependingKeys.Key, _configurationForType.ComponentType.ConfiguredType, invocation.Method, invocation.Arguments);
                var hasCalledOriginalMethod = false;
                var result = _cache.GetAndPutIfNonExisting(eventInfo, keyAndItsDependingKeys.DependingRemoveKeys, () =>
                {
                    invocation.Proceed();
                    hasCalledOriginalMethod = true;
                    return(invocation.ReturnValue);
                });
                if (!hasCalledOriginalMethod)
                {
                    invocation.ReturnValue = result;
                }
            }
        }