1
/// <summary>
2
/// 获取当前应用程序指定CacheKey的Cache值
3
/// </summary>
4
/// <param name="CacheKey"></param>
5
/// <returns></returns>
6
public static object GetCache(string CacheKey)
7
{
8
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
9
return objCache[CacheKey];
10
}
11
/// <summary>
12
/// 设置当前应用程序指定CacheKey的Cache值
13
/// </summary>
14
/// <param name="CacheKey"></param>
15
/// <param name="objObject"></param>
16
public static void SetCache(string CacheKey, object objObject)
17
{
18
System.Web.Caching.Cache objCache = HttpRuntime.Cache;
19
objCache.Insert(CacheKey, objObject);
20
21
}
22
读缓冲
23
DataTable downtb= null;
24
object objType = GetCache("downCache");//从缓存读取
25
if(objType == null)
26
{
27
//那么就把数据存储到缓冲区当中去
28
downtb = GetComList("select * from "表名").Tables[0];
29
SetCache("downCache",downtb);
30
}
31
else
32
{
33
downtb = (DataTable)objType;
34
}
35
/// <summary>
36
/// 将读区的数据放入缓层
37
/// </summary>
38
/// <param name="CacheName"></param>
39
/// <param name="CacheValue"></param>
40
public static void SetValue(string CacheName, object CacheValue)
41
{
42
if (HttpRuntime.Cache[CacheName] == null)
43
{
44
HttpRuntime.Cache.Add(CacheName, CacheValue, null, DateTime.Now.AddHours(10), TimeSpan.Zero, CacheItemPriority.NotRemovable, null);
45
}
46
else
47
{
48
HttpRuntime.Cache.Insert(CacheName, CacheValue, null, DateTime.Now.AddHours(10), TimeSpan.Zero);
49
}
50
}
51
52
/// <summary>2
/// 获取当前应用程序指定CacheKey的Cache值3
/// </summary>4
/// <param name="CacheKey"></param>5
/// <returns></returns>6
public static object GetCache(string CacheKey)7
{8
System.Web.Caching.Cache objCache = HttpRuntime.Cache;9
return objCache[CacheKey];10
}11
/// <summary>12
/// 设置当前应用程序指定CacheKey的Cache值13
/// </summary>14
/// <param name="CacheKey"></param>15
/// <param name="objObject"></param>16
public static void SetCache(string CacheKey, object objObject)17
{18
System.Web.Caching.Cache objCache = HttpRuntime.Cache;19
objCache.Insert(CacheKey, objObject);20
21
}22
读缓冲23
DataTable downtb= null;24
object objType = GetCache("downCache");//从缓存读取25
if(objType == null)26
{27
//那么就把数据存储到缓冲区当中去28
downtb = GetComList("select * from "表名").Tables[0];29
SetCache("downCache",downtb); 30
}31
else32
{33
downtb = (DataTable)objType;34
}35
/// <summary>36
/// 将读区的数据放入缓层37
/// </summary>38
/// <param name="CacheName"></param>39
/// <param name="CacheValue"></param>40
public static void SetValue(string CacheName, object CacheValue)41
{42
if (HttpRuntime.Cache[CacheName] == null)43
{44
HttpRuntime.Cache.Add(CacheName, CacheValue, null, DateTime.Now.AddHours(10), TimeSpan.Zero, CacheItemPriority.NotRemovable, null);45
}46
else47
{48
HttpRuntime.Cache.Insert(CacheName, CacheValue, null, DateTime.Now.AddHours(10), TimeSpan.Zero);49
}50
}51

52



浙公网安备 33010602011771号