public static MemoryCacheManager GetManager() { lock (lockobj)//控制多线程的并发问题 { if (_memoryCacheManager == null) { _memoryCacheManager = new MemoryCacheManager(); } } return(_memoryCacheManager); }
/// <summary> /// 该方法是获取一个新缓存对象 /// </summary> /// <param name="cacheName">MemoryCache名字</param> /// <returns></returns> public static MemoryCache GetMemoryCache(string cacheName) { if (MemoryCacheManager.GetManager().ContainCache(cacheName)) { return(MemoryCacheManager.GetManager().Get(cacheName)); } else { return(new MemoryCache(cacheName)); } }
private MemoryCache(string cacheName) { this._name = cacheName; this._cache = new Dictionary <string, MemoryCacheEntry>(); MemoryCacheManager.GetManager().Add(this); }
/// <summary>从MemoryCache中移除缓存对象(供MemoryCacheEntry的回调)</summary> /// <param name="cacheName"></param> /// <param name="key"></param> internal void RemoveCache(string cacheName, string key) { MemoryCacheManager.GetManager().Get(cacheName).RemoveCache(key); }