示例#1
0
 public static MemoryCacheManager GetManager()
 {
     lock (lockobj)//控制多线程的并发问题
     {
         if (_memoryCacheManager == null)
         {
             _memoryCacheManager = new MemoryCacheManager();
         }
     }
     return(_memoryCacheManager);
 }
示例#2
0
 /// <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));
     }
 }
示例#3
0
 private MemoryCache(string cacheName)
 {
     this._name  = cacheName;
     this._cache = new Dictionary <string, MemoryCacheEntry>();
     MemoryCacheManager.GetManager().Add(this);
 }
示例#4
0
 /// <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);
 }