Exemplo n.º 1
0
        public CachedItem GetAndPutIfNonExisting(EventInformation eventInformation, Func <IEnumerable <string> > dependingRemoveKeys, Func <object> originalMethod)
        {
            var cachedItem = (CachedItem)cache.Get(eventInformation.CacheKey);

            if (cachedItem != null)
            {
                _eventListenersCallback.OnCacheHit(cachedItem);
                return(cachedItem);
            }

            lock (lockObject(eventInformation))
            {
                var cachedItem2 = (CachedItem)cache.Get(eventInformation.CacheKey);
                if (cachedItem2 != null)
                {
                    _eventListenersCallback.OnCacheHit(cachedItem2);
                    return(cachedItem2);
                }
                var addedValue = executeAndPutInCache(eventInformation, dependingRemoveKeys(), originalMethod);
                _eventListenersCallback.OnCacheMiss(addedValue);
                return(addedValue);
            }
        }
Exemplo n.º 2
0
        public object GetAndPutIfNonExisting(KeyAndItsDependingKeys keyAndItsDependingKeys, CachedMethodInformation cachedMethodInformation, Func <object> originalMethod)
        {
            var cachedItem = (CachedItem)cache.Get(keyAndItsDependingKeys.Key);

            if (cachedItem != null)
            {
                _eventListenersCallback.OnCacheHit(cachedItem);
                return(cachedItem.CachedValue);
            }

            lock (lockObject)
            {
                var cachedItem2 = (CachedItem)cache.Get(keyAndItsDependingKeys.Key);
                if (cachedItem2 != null)
                {
                    _eventListenersCallback.OnCacheHit(cachedItem2);
                    return(cachedItem2.CachedValue);
                }
                var addedValue = executeAndPutInCache(keyAndItsDependingKeys, cachedMethodInformation, originalMethod);
                _eventListenersCallback.OnCacheMiss(addedValue);
                return(addedValue.CachedValue);
            }
        }