Exemplo n.º 1
0
        private CacheEntry <TResult> CreateEntry(TKey k, Func <ICacheContext <TKey>, TResult> context)
        {
            var entry          = new CacheEntry <TResult>();
            var currentContext = new DefaultCacheContext <TKey>(k, entry.AddToken);

            ICacheContext parentContext = null;

            try
            {
                parentContext = cacheContextAccessor.Current;
                cacheContextAccessor.Current = currentContext;

                entry.Result = context(currentContext);
            }
            finally
            {
                cacheContextAccessor.Current = parentContext;
            }
            entry.CompactTokens();
            return(entry);
        }
Exemplo n.º 2
0
        private CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire)
        {
            var entry   = new CacheEntry();
            var context = new AcquireContext <TKey>(k, entry.AddToken);

            IAcquireContext parentContext = null;

            try {
                // Push context
                parentContext = _cacheContextAccessor.Current;
                _cacheContextAccessor.Current = context;

                entry.Result = acquire(context);
            }
            finally {
                // Pop context
                _cacheContextAccessor.Current = parentContext;
            }
            entry.CompactTokens();
            return(entry);
        }
Exemplo n.º 3
0
        private CacheEntry CreateEntry(TKey k, Func <AcquireContext <TKey>, TResult> acquire)
        {
            var entry   = new CacheEntry();
            var context = new AcquireContext <TKey>(k, entry.AddToken);

            IAcquireContext parentContext = null;

            try
            {
                // Push context
                parentContext = _cacheContextAccessor.Current;
                _cacheContextAccessor.Current = context;
                entry.Result = acquire(context);
                //创建缓存
                var flag = _client.ExecuteStore(StoreMode.Set, k.ToString(), entry);
            }
            finally
            {
                // Pop context
                _cacheContextAccessor.Current = parentContext;
            }
            entry.CompactTokens();
            return(entry);
        }