| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | 
							- using Common;
 
- using System;
 
- using System.Collections;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using System.Web;
 
- using System.Web.Caching;
 
- namespace KC.Cache.WebCache
 
- {
 
-     public class WebCache:ICache
 
-     {
 
-         protected static volatile System.Web.Caching.Cache webCache = HttpRuntime.Cache;
 
-         private static int timeOut = ConfigHelper.GetValue("OutTime").TryToInt32();
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public void WriteCache<T>(string cacheKey, T value, int seconds = 0) where T : class
 
-         {
 
-             if (String.IsNullOrEmpty(cacheKey) || value == null)
 
-                 return;
 
-             if (seconds == 0)
 
-                 seconds = timeOut;
 
-             var callBack = new CacheItemRemovedCallback(onRemove);
 
-             webCache.Insert(cacheKey, value, null, System.DateTime.Now.AddSeconds(seconds), System.Web.Caching.Cache.NoSlidingExpiration, CacheItemPriority.High, callBack);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public T GetCache<T>(string cacheKey) where T : class
 
-         {
 
-             if (!String.IsNullOrEmpty(cacheKey))
 
-                 return (T)webCache.Get(cacheKey);
 
-             return default(T);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         public List<string> GetAllKeys()
 
-         {
 
-             List<string> list = new List<string>();
 
-             var enu = webCache.GetEnumerator();
 
-             while (enu.MoveNext())
 
-             {
 
-                 list.Add(enu.Key.ToString());
 
-             }
 
-             return list;
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         
 
-         public bool HasExpire(string cacheKey)
 
-         {
 
-             if (string.IsNullOrEmpty(cacheKey))
 
-                 return false;
 
-             return webCache[cacheKey] != null;
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         public void RemoveCache(string cacheKey)
 
-         {
 
-             if (!String.IsNullOrEmpty(cacheKey))
 
-                 webCache.Remove(cacheKey);
 
-         }
 
-         
 
-         
 
-         
 
-         
 
-         public void RemoveCache(List<string> keys)
 
-         {
 
-             if (keys.Count > 0)
 
-             {
 
-                 var enu = webCache.GetEnumerator();
 
-                 while (enu.MoveNext())
 
-                 {
 
-                     string key = enu.Key.ToString();
 
-                     if (keys.Where(p => p == key).Count() > 0)
 
-                     {
 
-                         RemoveCache(key);
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         #region MyRegion
 
-         public void onRemove(string key, object val, CacheItemRemovedReason reason)
 
-         {
 
-             switch (reason)
 
-             {
 
-                 case CacheItemRemovedReason.DependencyChanged:
 
-                     
 
-                     break;
 
-                 case CacheItemRemovedReason.Expired:
 
-                     
 
-                     break;
 
-                 case CacheItemRemovedReason.Removed:
 
-                     break;
 
-                 case CacheItemRemovedReason.Underused:
 
-                     break;
 
-                 default:
 
-                     break;
 
-             }
 
-         }
 
-         #endregion
 
-     }
 
- }
 
 
  |