另类的缓存技术(存储数据)

ExpandedBlockStart.gif 代码
 1  using  System;
 2  using  System.Web;
 3  using  System.Web.Caching;
 4 
 5  namespace  Mysoft.Cache
 6  {
 7       ///   <summary>
 8       ///  缓存生成类
 9       ///   </summary>
10       public   class  CacheControl
11      {
12           // const double CacheDuration = 60.0;
13 
14           private   static   double  _CacheDuration  =   1800.0 ;
15 
16           public   static   double  CacheDuration
17          {
18               get
19              {
20                   return  _CacheDuration;
21              }
22               set
23              {
24                  _CacheDuration  =  value;
25              }
26          }
27          
28           private   static   string  GetCacheKey( string  cacheKey,  string [] MasterCacheKeyArray)
29          {
30               return   string .Concat(MasterCacheKeyArray[ 0 ],  " - " , cacheKey);
31          }
32 
33           public   static   object  GetCacheItem( string  rawKey,  string [] MasterCacheKeyArray)
34          {
35               return  HttpRuntime.Cache[GetCacheKey(rawKey, MasterCacheKeyArray)];
36          }
37 
38           public   static   void  AddCacheItem( string  rawKey,  object  value,  string [] MasterCacheKeyArray)
39          {
40              System.Web.Caching.Cache DataCache  =  HttpRuntime.Cache;
41 
42               //  Make sure MasterCacheKeyArray[0] is in the cache - if not, add it
43               if  (DataCache[MasterCacheKeyArray[ 0 ]]  ==   null )
44              {
45                  DataCache[MasterCacheKeyArray[ 0 ]]  =  DateTime.Now;
46              }
47              CacheDependency dependency  =   new  CacheDependency( null , MasterCacheKeyArray);
48              DataCache.Insert(GetCacheKey(rawKey, MasterCacheKeyArray), value, dependency, DateTime.Now.AddSeconds(CacheDuration), System.Web.Caching.Cache.NoSlidingExpiration);
49          }
50 
51           public   static   void  InvalidateCache( string [] MasterCacheKeyArray)
52          {
53               //  Remove the cache dependency
54              HttpRuntime.Cache.Remove(MasterCacheKeyArray[ 0 ]);
55          }
56      }
57  }

 

转载于:https://www.cnblogs.com/skyz/archive/2010/03/24/1693507.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值