Exemplo n.º 1
0
 /// <summary>
 /// 获取键值对
 /// </summary>
 internal static object GetValue(string key, bool onlyMemoryCache = false)
 {
     lock (_dictLocksForReadCache.GetOrAdd(key, key))
     {
         object memoryCacheValue = MemoryCacheUtil.GetValue(key);
         if (memoryCacheValue != null)
         {
             return(memoryCacheValue);
         }
         else
         {
             if (!onlyMemoryCache)
             {
                 CacheData cacheData = FileCacheUtil.GetCacheData(key);
                 if (cacheData != null)
                 {
                     int expirationSeconds = (int)cacheData.updateTime.AddSeconds(cacheData.expirationSeconds).Subtract(DateTime.Now).TotalSeconds; //剩余过期时间
                     if (cacheData.expirationSeconds == 0)
                     {
                         expirationSeconds = 0;                                         //永不过期的情况
                     }
                     MemoryCacheUtil.SetValue(key, cacheData.value, expirationSeconds); //登录系统后(非首次登录),MemoryCache为空,FileCache不为空
                     return(cacheData.value);
                 }
             }
         }
         return(null);
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 保存键值对
 /// </summary>
 internal static void SetValue(string key, object value, bool onlyMemoryCache = false, int expirationSeconds = 0)
 {
     MemoryCacheUtil.SetValue(key, value, expirationSeconds);
     if (!onlyMemoryCache) //有的数据是不能缓存在文件中的,只能缓存在内存中
     {
         FileCacheUtil.SetValue(key, value, expirationSeconds);
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 删除全部缓存
 /// </summary>
 public static void DeleteAll()
 {
     MemoryCacheUtil.DeleteAll();
     FileCacheUtil.DeleteAll();
 }
Exemplo n.º 4
0
 /// <summary>
 /// 删除缓存
 /// </summary>
 public static void Delete(string key)
 {
     MemoryCacheUtil.Delete(key);
     FileCacheUtil.Delete(key);
 }