Пример #1
0
        public static bool Remove(string key, SimpleCacheType type)
        {
            var cachekey = CreateCacheKey(key, type);
            var removed  = HttpRuntime.Cache.Remove(cachekey);

            if (removed == null)
            {
                return(false);
            }
            return(true);
        }
Пример #2
0
        public static T GetCacheValue <T>(object key, SimpleCacheType cacheType, OnGetCacheValue <T> onGetValue, int timeOut = 9999)
        {
            string cacheKey = (int)cacheType + "#_#" + key.ToString();
            T      result   = default(T);

            try
            {
                result = (T)HttpRuntime.Cache[cacheKey];
            }
            catch
            {
                result = default(T);
            }
            if (result == null && onGetValue != null)
            {
                result = onGetValue();
                if (result != null)
                {
                    HttpRuntime.Cache.Insert(cacheKey, result, null, System.Web.Caching.Cache.NoAbsoluteExpiration, TimeSpan.FromSeconds(timeOut));
                }
            }
            return(result);
        }
Пример #3
0
        public static void Remove(object key, SimpleCacheType cacheType)
        {
            string cacheKey = (int)cacheType + "#_#" + key.ToString();

            HttpRuntime.Cache.Remove(cacheKey);
        }
Пример #4
0
 private static string CreateCacheKey(string key, SimpleCacheType type)
 {
     return(string.Concat(type, "-", key));
 }
Пример #5
0
 public static void Add(string key, object value, SimpleCacheType type)
 {
     Add(key, value, type, Cache.NoAbsoluteExpiration, new TimeSpan(0, 10, 10));
 }
Пример #6
0
 public static void Add(string key, object value, SimpleCacheType type, TimeSpan slidingExpiration)
 {
     Add(key, value, type, Cache.NoAbsoluteExpiration, slidingExpiration);
 }
Пример #7
0
 public static void Add(string key, object value, SimpleCacheType type, DateTime absoluteExpiration)
 {
     Add(key, value, type, absoluteExpiration, Cache.NoSlidingExpiration);
 }
Пример #8
0
        private static void Add(string key, object value, SimpleCacheType type, DateTime absoluteExpiration, TimeSpan slidingExpiration)
        {
            var cachekey = CreateCacheKey(key, type);

            HttpRuntime.Cache.Insert(cachekey, value, null, absoluteExpiration, slidingExpiration);
        }
Пример #9
0
        public static object Get(string key, SimpleCacheType type)
        {
            var cachekey = CreateCacheKey(key, type);

            return(HttpRuntime.Cache.Get(cachekey));
        }