bklLiudl
2024-07-23 675b8bcc4a3630d95e3d0b97d933e63442075ecb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
 
using System;
using System.Collections;
using System.Web;
using System.Web.Caching;
 
namespace Common
{
    public class CacheHelper
    {
        public static void InsertFile(string key, object obj, string fileName)
        {
            CacheDependency dep = new CacheDependency(fileName);
            HttpContext.Current.Cache.Insert(key, obj, dep);
        }
 
        public static void Insert(string key, object obj)
        {
            if (obj != null)
            {
                int expires = CommonHelper.GetInt(ConfigHelper.GetAppSettings("TimeCache"));
                HttpContext.Current.Cache.Insert(key, obj, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, expires, 0));
            }
        }
 
        public static bool IsExist(string strKey)
        {
            return HttpContext.Current.Cache[strKey] != null;
        }
 
        public static object GetCache(string key)
        {
            object result;
            if (string.IsNullOrEmpty(key))
            {
                result = null;
            }
            else
            {
                if (ConfigHelper.GetAppSettings("IsCache") == "false")
                {
                    result = null;
                }
                else
                {
                    result = HttpContext.Current.Cache.Get(key);
                }
            }
            return result;
        }
 
        public static T Get<T>(string key)
        {
            object obj = CacheHelper.GetCache(key);
            return (obj == null) ? default(T) : ((T)((object)obj));
        }
 
        public static void RemoveAllCache(string CacheKey)
        {
            Cache _cache = HttpRuntime.Cache;
            _cache.Remove(CacheKey);
        }
 
        public static void RemoveAllCache()
        {
            Cache _cache = HttpRuntime.Cache;
            IDictionaryEnumerator CacheEnum = _cache.GetEnumerator();
            while (CacheEnum.MoveNext())
            {
                _cache.Remove(CacheEnum.Key.ToString());
            }
        }
    }
}