Remove() public method

public Remove ( string key ) : object
key string
return object
Example #1
0
        public void Put(string key, object value)
        {
            Ensure.NotNullOrWhiteSpace(key, "key");
            Ensure.NotNull(value, "value");

            string cacheKey = GetCacheKey(key);

            if (cache[cacheKey] != null)
            {
                cache.Remove(cacheKey);
            }

            if (!rootCacheKeyStored)
            {
                StoreRootCacheKey();
            }

            cache.Insert(cacheKey,
                         new DictionaryEntry(key, value),
                         new CacheDependency(null, new[] { rootCacheKey }),
                         System.Web.Caching.Cache.NoAbsoluteExpiration,
                         this.Expiration,
                         this.Priority,
                         null);
        }
Example #2
0
 /// <summary>
 /// 是否存在缓存
 /// </summary>
 /// <param name="key">标识</param>
 /// <returns></returns>
 public override bool Contains(string key)
 {
     if (theState.ContainsKey(key))
     {
         CacheDependencyInfo info = theState[key];
         bool isOutTime           = info.createTime.AddMinutes(info.cacheMinutes) < DateTime.Now;
         if (!isOutTime && theCache[key] != null)
         {
             return(true);
         }
         else
         {
             lock (lockObj)
             {
                 try
                 {
                     theState.Remove(key);
                     if (isOutTime)
                     {
                         theCache.Remove(key);
                     }
                 }
                 catch
                 {
                     //errorCount++;
                 }
             }
         }
     }
     return(false);
 }
Example #3
0
 /// <summary>
 /// 清空全部缓存项
 /// </summary>
 public override void Clear()
 {
     foreach (string key in Keys)
     {
         cache.Remove(key);
     }
 }
Example #4
0
        public List <T> GetList <T>(string keyColl) where T : class
        {
            var list = new List <T>();

            if (this._cache.Get(keyColl) != null)
            {
                var keys    = (List <string>)_cache.Get(keyColl);
                var tmpKeys = new List <string>();
                if (!keys.Any())
                {
                    return(new List <T>());
                }
                foreach (var item in keys)
                {
                    tmpKeys.Add(item);
                    var data = (T)_cache.Get(item);
                    if (data != null)
                    {
                        list.Add(data);
                    }
                }
                if (tmpKeys.Any())
                {
                    var json = Newtonsoft.Json.JsonConvert.SerializeObject(tmpKeys) + "";
                    _cache.Remove(keyColl);
                    _cache.Insert(keyColl, json);
                }
            }
            return(list);
        }
Example #5
0
        /// <summary>
        /// Remove the object from the storage and clear the Xml assocated with
        /// the object
        /// </summary>
        /// <param name="xpath">hierarchical locatioin of the object</param>
        public static void Remove(string xpath)
        {
            lock (lockHelper)
            {
                XmlNode result = objectXmlMap.SelectSingleNode(PrepareXpath(xpath));
                //check if the xpath refers to a group(container) or
                //actual element for cached object
                if (result.HasChildNodes)
                {
                    //remove all the cached object in the hastable
                    //and remove all the child nodes
                    XmlNodeList objects  = result.SelectNodes("*[@objectId]");
                    string      objectId = "";
                    foreach (XmlNode node in objects)
                    {
                        objectId = node.Attributes["objectId"].Value;
                        node.ParentNode.RemoveChild(node);
                        //use cache strategy to remove the objects from the
                        //underlying storage
                        //     cs.RemoveObject(objectId);
                        webCache.Remove(objectId);
                    }
                }
                else
                {
                    //just remove the element node and the object associate with it
                    string objectId = result.Attributes["objectId"].Value;
                    result.ParentNode.RemoveChild(result);
                    //    cs.RemoveObject(objectId);

                    webCache.Remove(objectId);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Clear the Cache
        /// </summary>
        /// <exception cref="T:NHibernate.Cache.CacheException"></exception>
        public void Clear()
        {
            //remove the root cache item, this will cause all of the individual items to be removed from the cache
            _webCache.Remove(_rootCacheKey);
            _isRootItemCached = false;

            log.Debug("All items cleared from the cache.");
        }
Example #7
0
 /// <summary>
 /// 删除缓存对象
 /// </summary>
 /// <param name="objId">对象的关键字</param>
 public virtual void RemoveObject(string objId)
 {
     if (objId == null || objId.Length == 0)
     {
         return;
     }
     webCache.Remove(objId);
 }
Example #8
0
 public void Remove(string key)
 {
     if (string.IsNullOrEmpty(key))
     {
         return;
     }
     cache.Remove(key);
 }
Example #9
0
        public void Clear()
        {
            IDictionaryEnumerator enumerator = cache.GetEnumerator();

            while (enumerator.MoveNext())
            {
                cache.Remove(enumerator.Key.ToString());
            }
        }
Example #10
0
        /// <summary>
        /// 清空Cache
        /// </summary>
        public static void Clear()
        {
            IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();

            while (CacheEnum.MoveNext())
            {
                _cache.Remove(CacheEnum.Key.ToString());
            }
        }
        /// <summary>
        /// Clears everything in umbraco's runtime cache, which means that not only
        /// umbraco content is removed, but also other cache items from pages running in
        /// the same application / website. Use with care :-)
        /// </summary>
        public override void ClearAllCache()
        {
            var cacheEnumerator = _cache.GetEnumerator();

            while (cacheEnumerator.MoveNext())
            {
                _cache.Remove(cacheEnumerator.Key.ToString());
            }
        }
Example #12
0
        /// <summary>
        /// 从缓存中删除某一项
        /// </summary>
        /// <param name="key">键值</param>
        /// <exception cref="System.ArgumentNullException">缓存的key不能为空</exception>
        public void Remove(string key)
        {
            if (string.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("缓存的key不能为空");
            }

            cache.Remove(key);
        }
        internal void Remove(string cacheId, string key, CacheRemoveOptions options)
        {
            Platform.CheckForNullReference(key, "key");
            Platform.CheckForNullReference(options, "options");

            var cacheKey = GetItemCacheKey(cacheId, options.Region, key);

            _cache.Remove(cacheKey);
        }
Example #14
0
        /// <inheritdoc />
        public void Remove(object key)
        {
            if (key == null)
            {
                throw new ArgumentNullException(nameof(key));
            }
            var cacheKey = GetCacheKey(key);

            Log.Debug("removing item with key: {0}", cacheKey);
            _cache.Remove(cacheKey);
        }
Example #15
0
        //建立回调委托的一个实例
        public void onRemove(string key, object val, CacheItemRemovedReason reason)
        {
            try
            {
                switch (reason)
                {
                case CacheItemRemovedReason.DependencyChanged:
                {
                    break;
                }

                case CacheItemRemovedReason.Expired:
                {
                    CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(this.onRemove);

                    webCache.Remove(key);
                    webCache.Insert(key, val, null, System.DateTime.Now.AddMinutes(TimeOut),
                                    System.Web.Caching.Cache.NoSlidingExpiration,
                                    System.Web.Caching.CacheItemPriority.High,
                                    callBack);
                    break;
                }

                case CacheItemRemovedReason.Removed:
                {
                    CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(this.onRemove);

                    webCache.Insert(key, val, null, System.DateTime.Now.AddMinutes(TimeOut),
                                    System.Web.Caching.Cache.NoSlidingExpiration,
                                    System.Web.Caching.CacheItemPriority.High,
                                    callBack);

                    break;
                }

                case CacheItemRemovedReason.Underused:
                {
                    CacheItemRemovedCallback callBack = new CacheItemRemovedCallback(this.onRemove);

                    webCache.Insert(key, val, null, System.DateTime.Now.AddMinutes(TimeOut),
                                    System.Web.Caching.Cache.NoSlidingExpiration,
                                    System.Web.Caching.CacheItemPriority.High,
                                    callBack);
                    break;
                }

                default: break;
                }
            }
            catch
            {; }
            //如需要使用缓存日志,则需要使用下面代码
            myLogVisitor.WriteLog(this, key, val, reason);
        }
Example #16
0
 public bool DeleteCache(string key)
 {
     try
     {
         _cache.Remove(key);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #17
0
 public override bool Remove(string key)
 {
     if (cache == null)
     {
         return(false);
     }
     else
     {
         var value = cache.Remove(key);
         return(true);
     }
 }
Example #18
0
        /// <summary>
        /// 清除所有缓存
        /// </summary>
        public static void Clear()
        {
            IDictionaryEnumerator enumerator = Cache.GetEnumerator();
            ArrayList             list       = new ArrayList();

            while (enumerator.MoveNext())
            {
                list.Add(enumerator.Key);
            }
            foreach (string str in list)
            {
                Cache.Remove(str);
            }
        }
Example #19
0
        /// <summary>
        /// 清空所有缓存
        /// </summary>
        public static void Clear()
        {
            IDictionaryEnumerator enumerator = _cache.GetEnumerator();
            List <string>         list       = new List <string>();

            while (enumerator.MoveNext())
            {
                list.Add(enumerator.Key.ToString());
            }
            foreach (string str in list)
            {
                _cache.Remove(str);
            }
            OnWebCacheClear();
        }
Example #20
0
 public void Flush()
 {
     lock (m_SyncObj)
     {
         try
         {
             foreach (string key in CacheKeys)
             {
                 cache.Remove(key);
             }
             CacheKeys.Clear();
         }
         catch (Exception) { }
     }
 }
Example #21
0
        /// <summary>
        /// Removes all items from the Cache
        /// </summary>
        public static void Clear()
        {
            var cacheEnum = Cache.GetEnumerator();
            var al        = new List <object>();

            while (cacheEnum.MoveNext())
            {
                al.Add(cacheEnum.Key);
            }

            foreach (string key in al)
            {
                Cache.Remove(key);
            }
        }
Example #22
0
        /// <summary>
        /// 从Cache中移除所有项目
        /// </summary>
        public static void Clear()
        {
            IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
            List <object>         al        = new List <object>();

            while (CacheEnum.MoveNext())
            {
                al.Add(CacheEnum.Key);
            }

            foreach (string key in al)
            {
                _cache.Remove(key);
            }
        }
Example #23
0
        /// <summary>
        /// 清空所有数据
        /// </summary>
        public static void Clear()
        {
            IDictionaryEnumerator cacheEnum = CacheContainer.GetEnumerator();
            ArrayList             arrayList = new ArrayList();

            while (cacheEnum.MoveNext())
            {
                arrayList.Add(cacheEnum.Key);
            }

            foreach (string key in arrayList)
            {
                CacheContainer.Remove(key);
            }
        }
Example #24
0
        ///// <summary>
        ///// 是否存在cacheKey的缓存项
        ///// </summary>
        //public static bool Contains(string cacheKey)
        //{
        //    IDictionaryEnumerator cacheEnum = _cache.GetEnumerator();
        //    while (cacheEnum.MoveNext())
        //    {
        //        if (cacheEnum.Key.ToString().Equals(cacheKey, StringComparison.CurrentCultureIgnoreCase))
        //            return true;
        //    }
        //    return false;
        //}

        /// <summary>
        /// 从缓存中清除所有缓存项
        /// </summary>
        public static void Clear()
        {
            IDictionaryEnumerator cacheEnum = _cache.GetEnumerator();
            List <string>         keys      = new List <string>();

            while (cacheEnum.MoveNext())
            {
                keys.Add(cacheEnum.Key.ToString());
            }

            foreach (string key in keys)
            {
                _cache.Remove(key);
            }
        }
Example #25
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserInfo userInfo, BaseAreaEntity entity, out string statusCode, out string statusMessage)
        {
            int result = 0;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager   = new BaseAreaManager(dbHelper, userInfo);
                result        = manager.Update(entity, out returnCode);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;

            // 处理缓存优化性能
            System.Web.Caching.Cache cache = HttpRuntime.Cache;
            string cacheObject             = string.Empty;

            if (string.IsNullOrEmpty(entity.ParentId))
            {
                cacheObject = "AreaProvince";
            }
            else
            {
                cacheObject = "Area" + entity.ParentId;
            }
            cache.Remove(cacheObject);

            return(result);
        }
Example #26
0
 public static void ClearCachedTemplate(int templateID)
 {
     if (templateCache["template" + templateID.ToString()] != null)
     {
         templateCache.Remove("template" + templateID.ToString());
     }
 }
Example #27
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 /// <param name="cacheKey">缓存键值</param>
 public void RemoveCache(string cacheKey)
 {
     if (!string.IsNullOrEmpty(cacheKey))
     {
         cache.Remove(cacheKey);
     }
 }
Example #28
0
File: Cache.cs Project: ngocpq/MHX2
 public void Delete(string cache_key)
 {
     if (Exists(cache_key))
     {
         cache.Remove(cache_key);
     }
 }
Example #29
0
 private void LocalClearItem(string key)
 {
     if (!String.IsNullOrWhiteSpace(key))
     {
         _Cache.Remove(key);
     }
 }
Example #30
0
 public void InvalidateCacheItem(string cacheKey)
 {
     if (_cache.Get(cacheKey) != null)
     {
         _cache.Remove(cacheKey);
     }
 }
Example #31
0
 public static void ClearCache(Cache cache)
 {
     var itms = GetAllUsers(cache);
     foreach (var itm in itms)
     {
         var email = itm.Value["email"].ReadAs<string>();
         cache.Remove(email);
     }
 }
 public static void Flush(string name, Cache cache)
 {
     var cacheKey = CACHE_PREFIX + name;
     cache.Remove(cacheKey);
 }
 public void RemoveCache(Cache cache, string cacheKey, int? tenantId = null)
 {
     string key = GetTenantCacheKey(cacheKey, tenantId);
     if (cache[key] != null)
     {
         cache.Remove(key);
     }
 }
Example #34
0
 public static void Flush(string feedUri, Cache cache)
 {
     var cacheKey = CACHE_PREFIX + feedUri;
     cache.Remove(cacheKey);
 }