/// <summary> /// 清除全部 /// </summary> public void Clear() { CACHE_POOL.Clear(); if (this.Timeout > 0) { CACHE_POOL_CreateTime.Clear(); } }
/// <summary> /// 移出缓存 /// </summary> /// <param name="key"></param> /// <returns></returns> public TValue Remove(TKey key) { TValue value; CACHE_POOL.TryRemove(key, out value); if (CACHE_POOL_LastAccessTime != null) { DateTime lastAccessTime; CACHE_POOL_LastAccessTime.TryRemove(key, out lastAccessTime); } if (CACHE_POOL_CreateTime != null) { DateTime createTime; CACHE_POOL_CreateTime.TryRemove(key, out createTime); } return(value); }
/// <summary> /// 添加/更新缓存 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <param name="value"></param> public void Set(TKey key, TValue value) { if (!IsDefault <TKey>(key)) { if (CACHE_POOL.ContainsKey(key)) { CACHE_POOL[key] = value; if (CACHE_POOL_CreateTime != null) { CACHE_POOL_CreateTime[key] = DateTime.Now; } } else { CACHE_POOL.TryAdd(key, value); if (CACHE_POOL_CreateTime != null) { CACHE_POOL_CreateTime.TryAdd(key, DateTime.Now); } } } }