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

52

 
                     
                    
                 
                    
                 


 
             
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号