Cache总义
Cache用法之页面声明







Cache用法之代码控制
HttpCachePolicy类是专门用来控件Cache的,可以用Response.Cahce来访问这个类的实例



-----------------------以上都是缓存页面的,下面是缓存数据的----------------------------
Cache类的生存周期等于应用程序的生命周期
三种用法
1:存:Cache["key"] = MyData;取:
MyData = Cache["key"];
if(MyData != null)
use(MyData);
此法存入Cache的数据生命周期等于应用程序生命周期,不支持清除、过期、依赖性等功能。
2:存:
Cache.Insert(
string key,
object value,
CacheDependency dependencies,//依赖,设置缓存有效的依赖性,比如设置和一个文件相关,文件一变,就失效
DateTime absoluteExpireation, //设置固定的过期时间
TimeSpan slidingExpiration, //设置最后一次访问后多长时间过期
CachePriority priority, //设置内存不足,缓存自动清除时,缓存的重要性,可不可以清除
CacheItemRemovedCallback onRemoveCallback // 设置在清除时引发的事件
)
Example:




Caching.CacheItemPriority.NotRemovable,null);
// AboveNormal|BelowNormal|Default|High|Low|Normal|NotRemovable







DateTime.Now.AddDays(1),Cache.NoSlidingExpiration,CacheItemPriority.High,
new CacheItemRemovedCallback(this.RemovedCallback));
清除就可以用Cache.Remove("key");方法
3:
Cache.Add方法,用法和Insert差不多,区别在于Add碰到该key原来有赋过值会失败,Insert则不会,而会替换原有值;Add会返回被缓存数据项,Insert不会