使用Cache缓存Page页面
来源:互联网 发布:淘宝夜抢购报名入口 编辑:程序博客网 时间:2024/04/30 06:17
使用Cache:
<%@ OutputCache Duration="15" VaryByPara="None" %>
页面使用Cache,Cache的有效期为15 seconds
使用代码表示,放在Page_Load里面:
//
//Cache Manager可以控制这个页面
//
Response.Cache.SetCacheability(HttpCacheability.Public);
//
//告诉Cache Manager,页面的有效期为当前时间+15秒
//
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
当使用@OutputCache时,Asp.Net 调用页面对象的InitOutPutCache(),将Cache转换为对应的HttpCachePolicy()。
所有对此页面的请求,都是访问Cache中的信息,直到Cache的生存周期结束。
对于页面的Cache的使用范围和存储位置:
Cache的使用范围可以使用Location属性,或者HttpResponse.Cache对象来设置。
<%@ OutputCache Duration="15" Location="Client" VaryByPara="None" %>
或者
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheabiligy.Private);
默认状况下,Cache可以存放在任意位置,如:用户的浏览器,响应的服务器,或者代理服务器
<%@ OutputCache Duration="15" Location="Any" VaryByPara="None" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Public);
如果禁止Cache,那么可以:
<%@ OutputCache Location="None" VaryByPara="None" %>
等效于:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
使Cache存在于响应的服务器:
<%@ OutputCache Duration="15" Location="Server" VaryByPara="None" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Server);
使Cache存在于Client:
<%@ OutputCache Duration="15" Location="Any" VaryByParam="Client" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Private);
如果使用了集群,那么对于Cache的控制,应该由代理服务器来完成:
<%@ OutputCache Duration="15" Localtion="Location" VaryByPara="Client" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetNoServerCaching();
注意:使用Location属性,不能保证任何页面的用户控件都使用定义的Location位置,同样:如果禁止使用Cache,也不能保证页面的用户控件都禁用了Cache。
<%@ OutputCache Duration="15" VaryByPara="None" %>
页面使用Cache,Cache的有效期为15 seconds
使用代码表示,放在Page_Load里面:
//
//Cache Manager可以控制这个页面
//
Response.Cache.SetCacheability(HttpCacheability.Public);
//
//告诉Cache Manager,页面的有效期为当前时间+15秒
//
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
当使用@OutputCache时,Asp.Net 调用页面对象的InitOutPutCache(),将Cache转换为对应的HttpCachePolicy()。
所有对此页面的请求,都是访问Cache中的信息,直到Cache的生存周期结束。
对于页面的Cache的使用范围和存储位置:
Cache的使用范围可以使用Location属性,或者HttpResponse.Cache对象来设置。
<%@ OutputCache Duration="15" Location="Client" VaryByPara="None" %>
或者
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheabiligy.Private);
默认状况下,Cache可以存放在任意位置,如:用户的浏览器,响应的服务器,或者代理服务器
<%@ OutputCache Duration="15" Location="Any" VaryByPara="None" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Public);
如果禁止Cache,那么可以:
<%@ OutputCache Location="None" VaryByPara="None" %>
等效于:
Response.Cache.SetCacheability(HttpCacheability.NoCache);
使Cache存在于响应的服务器:
<%@ OutputCache Duration="15" Location="Server" VaryByPara="None" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Server);
使Cache存在于Client:
<%@ OutputCache Duration="15" Location="Any" VaryByParam="Client" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Private);
如果使用了集群,那么对于Cache的控制,应该由代理服务器来完成:
<%@ OutputCache Duration="15" Localtion="Location" VaryByPara="Client" %>
等效于:
Response.Cache.SetExpires(DateTime.Now.AddSeconds(15));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetNoServerCaching();
注意:使用Location属性,不能保证任何页面的用户控件都使用定义的Location位置,同样:如果禁止使用Cache,也不能保证页面的用户控件都禁用了Cache。
- 使用Cache缓存Page页面
- 使用Cache缓存Page页面
- 使用Cache缓存Page页面
- Page Cache(页面缓存)
- WebKit的页面缓存 -- Page Cache
- 个人技术作品 - PHP Page Cache 页面缓存类
- 转 WebKit的页面缓存机制I – 基础(WebKit Page Cache I – The Basics)
- WebKit的页面缓存 -- WebKit Page Cache I – The Basics
- 页面缓冲(Page Cache)的管理
- Cache缓存使用相关
- 缓存的使用Cache
- 缓存cache使用示例
- 缓存(Cache)使用用法
- page cache
- Page.Cache
- page cache
- Nginx Proxy Cache的slab page内存缓存机制
- 使用com.google.common.cache.Cache缓存
- 狼
- 虚拟机和主机的连通(外部主机可访问虚拟机)
- C++ STL标准入门汇总
- 2011 大连网络赛 The 36th ACM/ICPC Asia Regional Dalian Site —— Online Contest 解题报告
- mac ox,我来了
- 使用Cache缓存Page页面
- 代码注入的三种方法
- cantor的数表
- Fedora 15 Nvidia官方显卡驱动的安装
- MyEclipse 快捷键及经验总结(留着,不记得时候看看,很强大)
- C#学习笔记28——C# 插件编程
- MFC ListControl控件用法
- 黑马程序员0904_多线程部分+API部分
- Windows Socket IO 模型