예제 #1
0
        internal object InternalExcecute(Expression expression, Func <object> getValue)
        {
            var cacheKey = _cacheKey ?? ExpressionKeyGenerator.GetKey(expression);

            // Query cache.
            object cachedValue;
            var    isCached = _container.Get(cacheKey, out cachedValue);

            if (isCached)
            {
                // Return item from cache.
                _invalidator.OnCacheHit(_container, _query, cacheKey, cachedValue);
                return(cachedValue);
            }

            // If not cached, cache item.
            _invalidator.OnCacheMiss(_container, _query, cacheKey);
            var value = getValue();

            // Cache item.
            if (_container.SupportsDurationInvalidation && _invalidator.UsesDuration)
            {
                _container.Set(cacheKey, value, _invalidator.Duration);
            }
            else
            {
                _container.Set(cacheKey, value);
            }

            _invalidator.OnCacheRefresh(_container, _query, cacheKey, value);

            return(value);
        }
예제 #2
0
        internal void Invalidate()
        {
            var cacheKey = _cacheKey ?? ExpressionKeyGenerator.GetKey(_query.Expression);

            _container.Delete(cacheKey);
        }