HttpContext.Cache和Application的区别
来源:互联网 发布:小学生自学游戏编程 编辑:程序博客网 时间:2024/05/16 08:37
用户会话级的Session
cache就是具有所有application的优点,然后又有自己的特点
1.基于依赖性的终止.使用关键字作为依赖项,关键字一变,cache内容无效并自动删除。
2.锁定管理:和application一样,不过不是使用命令 ,内部自动完成锁和解锁
3.资源管理:不使用时,自动删除
4.回调:很特殊哦,允许我们当删除了cache后,仍然可以调用。
5.隐式插入,显式插入:隐士的就是和application一样,cache["myname"]="abc";
显示的就是cache.insert().....
每个项目都有一些全局,常用的信息,而这些信息如果在每次使用时都载入,那必将耗费很大的资源,特别是对访问压力大的系统。因此,这个情况中,把这些全局信息放到缓存中是很必要的,放在缓存中可以使得数据能够很快的被读取,节省了很多宝贵的CPU和IO。
项目中通常是用application 和cache来实现缓存的功能。他们的用法分别为:
1)application:
application["test"] = "this is a application message!";
2)cache
Cache.Add("Key1", "Value");
两种用法都很相似,都是采用名/值对的方式来保存数据,而在读取数据时也只要用 键 就可以获取缓存的值。
而2种相比,到底哪种更有优势呢? 答案是CACHE在使用上更具有灵活性。特点如下:
1。自有的按时更新缓存的机制
有的项目需要定时获取最新数据的需求,如天气预报,可能间隔10分钟 就要读取一次需求,那这可以利用CACHE本身的方法来实现。
//监视某个时间
public void CreateDependency(Object sender, EventArgs e) {
// Create a DateTime object.
DateTime dt = DateTime.Now.AddSeconds(10);
// Create a cache entry.
Cache["key1"] = "Value 1";
CacheDependency dependency = new CacheDependency(null, dt);
Cache.Insert("key2", "Value 2", dependency);
DisplayValues();
}
2.当缓存的源修改时,可以重新更新缓存。这个缓存源可以是变量,也可以是文件,或者目录。
//监视某个变量
public void CreateDependency(Object sender, EventArgs e) {
// Create a DateTime object.
//DateTime dt = DateTime.Now.AddSeconds(10);
// Create a cache entry.
Cache["key1"] = "Value 1";
// Make key2 dependent on key1.
String[] dependencyKey = new String[1];
dependencyKey[0] = "key1";
CacheDependency dependency = new CacheDependency(null, dependencyKey, null);
Cache.Insert("key2", "Value 2", dependency);
DisplayValues();
}
3.同时以多种搭配来自动更新缓存,如同时监视某个文件,并且在指定间隔的时间内自动更新。
//监视某个时间和变量
public void CreateDependency(Object sender, EventArgs e) {
// Create a DateTime object.
DateTime dt = DateTime.Now.AddSeconds(10);
// Create a cache entry.
Cache["key1"] = "Value 1";
// Make key2 dependent on key1.
String[] dependencyKey = new String[1];
dependencyKey[0] = "key1";
CacheDependency dependency = new CacheDependency(null, dependencyKey, dt);
Cache.Insert("key2", "Value 2", dependency);
DisplayValues();
}
比起APPLICATION来,CACHE更显得灵活。
- HttpContext.Cache和Application的区别
- HttpContext.Cache和Application的区别
- HttpContext.Cache和HttpRuntime.Cache的区别
- HttpContext.Cache和HttpRuntime.Cache的区别
- HttpContext.Current.Cache 和HttpRuntime.Cache的区别
- HttpContext.Current.Cache 和HttpRuntime.Cache的区别
- HttpContext.Current.Cache 和HttpRuntime.Cache的区别
- HttpContext.Current.Cache和HttpRuntime.Cache的区别
- HttpContext.Current.Cache 与HttpRuntime.Cache的区别
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache 和 HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache
- HttpContext.Cache和HttpRuntime.Cache中的Cache
- APPlication,Session,Cookie,ViewState和Cache之间的区别
- APPlication,Session,Cookie,ViewState和Cache之间的区别
- APPlication,Session,Cookie,ViewState和Cache之间的区别
- js ==与===区别(两个等号与三个等号)
- html input 设置为只读属性
- 表单设计
- 在spring security3中使用自定义的MD5和salt进行加密
- Ruby相关的比较cool的工具和代码收集
- HttpContext.Cache和Application的区别
- 福大数据结构与算法实验题 1.2 单词背诵(map实现)
- 南海之争 近代史 课程设计 辩论 课程展示 期末论文 俄格之战下的中越南海之争相关资料
- ORA-01034和ORA-27101的一种解决方法
- VC/MFC之ListCtrl控件使用经验总结
- 技术人员应真正学会的第二课程
- HttpSessionListener和HttpSessionBindingListener的区别
- XML
- Linux 下定时器的实现方式分析