예제 #1
0
        public void Add(string key, object value, params ICacheItemExpiration[] expirations)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentException("参数[key]不能为空或空字符串");
            }

            CacheItem cacheItemBeforeLock = null;

            lock (inMemoryCache.SyncRoot)
            {
                if (!inMemoryCache.Contains(key))
                {
                    cacheItemBeforeLock = new CacheItem(key, value, expirations);
                    inMemoryCache[key] = cacheItemBeforeLock;
                }
                else
                {
                    cacheItemBeforeLock = (CacheItem)inMemoryCache[key];
                    try
                    {
                        cacheItemBeforeLock.Replace(value, expirations);
                        inMemoryCache[key] = cacheItemBeforeLock;
                    }
                    catch
                    {
                        inMemoryCache.Remove(key);
                        throw;
                    }
                }
            }
        }
예제 #2
0
 public void Initialize(CacheItem owningCacheItem)
 {
 }
예제 #3
0
 public void Initialize(CacheItem owningCacheItem)
 {
 }