コード例 #1
0
        void ClearCache(string cacheType)
        {
            if (cacheType == "me")
            {
                _cache.Remove(CacheKey());
                nbWarning.Text = string.Format(
                    "Your cache key has been cleared. Click <a href=\"{0}\">here</a> to reload the page.",
                    new PageReference(RockPage.PageId).BuildUrl());
            }
            else if (cacheType == "block")
            {
                string key  = BlockCacheKey();
                var    keys = _cache.Where(kvp => kvp.Key.StartsWith(key)).Select(kvp => kvp.Key).ToList();

                foreach (var k in keys)
                {
                    _cache.Remove(k);
                }

                nbWarning.Text = string.Format(
                    "{1} cache keys have been cleared. Click <a href=\"{0}\">here</a> to reload the page.",
                    new PageReference(RockPage.PageId).BuildUrl(),
                    keys.Count);
            }
            else
            {
                nbWarning.Text = "Cannot clear cache, unknown cache type.";
            }
        }
コード例 #2
0
        public bool Rename(string key, string newKey)
        {
            if (string.IsNullOrWhiteSpace(newKey))
            {
                throw new ArgumentNullException("newKey");
            }

#if !CORE_CLR
            var orignalValue = _innerCache.Remove(key);

            if (orignalValue != null)
            {
                _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration);
            }

            return(orignalValue != null);
#else
            object orignalValue;

            if (_innerCache.TryGetValue(key, out orignalValue))
            {
                _innerCache.Remove(key);
                _innerCache.Set(newKey, orignalValue, new MemoryCacheEntryOptions
                {
                    AbsoluteExpiration = DateTimeOffset.MaxValue
                });
            }

            return(orignalValue != null);
#endif
        }
コード例 #3
0
ファイル: MemoryCache.cs プロジェクト: hongweichang/NFinal2
        public override void Remove(string key)
        {
#if !(NETCORE || CORE)
            _memoryCache.Remove(key);
#else
            _memoryCache.Remove(key);
#endif
        }
コード例 #4
0
 public static void CacheEkle(string key, object value, int expireAsMinute)
 {
     if (_cache.Any(x => x.Key == key))
     {
         _cache.Remove(key);
     }
     _cache.Add(key, value, DateTimeOffset.Now.AddMinutes(expireAsMinute));
 }
コード例 #5
0
        private async Task <T> GetOrSetMemory <T>(string key, TimeSpan timespan, Func <Task <T> > valueFactory)
        {
            var newValue = new Lazy <Task <T> >(valueFactory);
            var oldValue = _memorycache.AddOrGetExisting(key, newValue, DateTimeOffset.UtcNow.Add(timespan)) as Lazy <Task <T> >;

            try
            {
                return(await(oldValue ?? newValue).Value.ConfigureAwait(false));
            }
            catch
            {
                _memorycache.Remove(key);
                return(default(T));
            }
        }
コード例 #6
0
        public bool Rename(string key, string newKey)
        {
            if (string.IsNullOrWhiteSpace(newKey))
            {
                throw new ArgumentNullException("newKey");
            }

            var orignalValue = _innerCache.Remove(key);

            if (orignalValue != null)
            {
                _innerCache.Add(newKey, orignalValue, System.Runtime.Caching.ObjectCache.InfiniteAbsoluteExpiration);
            }

            return(orignalValue != null);
        }
コード例 #7
0
 /// <summary>
 /// Delete cache value from key
 /// </summary>
 /// <param name="key"></param>
 public static void Delete(string key)
 {
     System.Runtime.Caching.MemoryCache memoryCache = System.Runtime.Caching.MemoryCache.Default;
     if (memoryCache.Contains(key))
     {
         memoryCache.Remove(key);
     }
 }
コード例 #8
0
        public object Remove(string key)
        {
            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            return(_cache.Remove(key));
        }
コード例 #9
0
ファイル: MemoryCache.cs プロジェクト: ilkerhalil/KVLite
        /// <summary>
        ///   Clears this instance or a partition, if specified.
        /// </summary>
        /// <param name="partition">The optional partition.</param>
        /// <param name="cacheReadMode">The cache read mode.</param>
        /// <returns>The number of items that have been removed.</returns>
        protected override long ClearInternal(string partition, CacheReadMode cacheReadMode = CacheReadMode.IgnoreExpiryDate)
        {
            // We need to make a snapshot of the keys, since the cache might be used by other
            // processes. Therefore, we start projecting all keys.
            var keys = _store.Select(x => x.Key);

            // Then, if a partition has been specified, we select only those keys that belong to that partition.
            if (partition != null)
            {
                keys = keys.Where(k => DeserializeCacheKey(k).Partition == partition);
            }

            // Now we take the snapshot of the keys.
            var keysArray = keys.ToArray();

            // At last, we can remove them safely from the store itself.
            foreach (var key in keys)
            {
                _store.Remove(key);
            }

            return(keysArray.LongLength);
        }
コード例 #10
0
 public static T GetOrSet <T>(string key, Func <T> valueFactory, TimeSpan expiry)
 {
     try
     {
         var newValue = new Lazy <T>(valueFactory);
         var oldValue = _memorycache.AddOrGetExisting(key, newValue, DateTimeOffset.UtcNow.Add(expiry)) as Lazy <T>;
         return((oldValue ?? newValue).Value);
     }
     catch
     {
         _memorycache.Remove(key);
         return(default(T));
     }
 }
コード例 #11
0
ファイル: CertCache.cs プロジェクト: buweixiaomi/DydCert
        private void SetCertCahe()
        {
            System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default;
            if (tempmanagecache == null)
            {
                tempmanagecache = new List <CertCacheItem>();
            }
            if (mcache.Get(cachetypename) != null)
            {
                mcache.Remove(cachetypename);
            }

            bool r = mcache.Add(cachetypename, tempmanagecache.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes)));

            if (!r)
            {
                mcache = null;
            }
        }
コード例 #12
0
ファイル: AppCache.cs プロジェクト: buweixiaomi/DydCert
        private void SetCache()
        {
            System.Runtime.Caching.MemoryCache mcache = System.Runtime.Caching.MemoryCache.Default;
            if (cacheapps == null)
            {
                cacheapps = new List <AppModel>();
            }
            if (mcache.Get(getcachename) != null)
            {
                mcache.Remove(getcachename);
            }

            bool r = mcache.Add(getcachename, cacheapps.CloneList(), new DateTimeOffset(DateTime.Now.AddMinutes(expiresminutes)));

            if (!r)
            {
                mcache = null;
            }
        }
コード例 #13
0
 /// <inheritdoc />
 public void Remove(string key)
 {
     _memoryCache.Remove(key);
 }
コード例 #14
0
ファイル: Cache.cs プロジェクト: PowerOlive/Atlas-5
 public void Remove(string key)
 {
     cache.Remove(key);
 }
コード例 #15
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public bool Delete(string key)
 {
     Cache.Remove(key);
     return(true);
 }
コード例 #16
0
        public void Remove(string key)
        {
            System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key));

            _cache.Remove(key);
        }
コード例 #17
0
 /// <inheritdoc />
 public bool Remove(string key)
 {
     return(key != null && cache.Remove(key) != null);
 }
コード例 #18
0
ファイル: DBGuiInterface.cs プロジェクト: mlof/ED-IBE
 public void SetIniValue(string initKey, string initValue)
 {
     m_DBCon.setIniValue(m_InitGroup, initKey, initValue);
     m_SettingsCache.Remove(initKey + "|" + initValue);
 }
コード例 #19
0
        public bool Remove(string key)
        {
            var item = _cache.Remove(key);

            return(item != null);
        }
コード例 #20
0
 public void Delete(string key)
 {
     _cache.Remove(key);
 }