惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
V
Vulnerabilities – Threatpost
Last Week in AI
Last Week in AI
I
InfoQ
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Help Net Security
D
Docker
www.infosecurity-magazine.com
www.infosecurity-magazine.com
B
Blog RSS Feed
Forbes - Security
Forbes - Security
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Latest news
Latest news
S
SegmentFault 最新的问题
J
Java Code Geeks
C
CXSECURITY Database RSS Feed - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
F
Full Disclosure
Engineering at Meta
Engineering at Meta
AWS News Blog
AWS News Blog
月光博客
月光博客
Cisco Talos Blog
Cisco Talos Blog
V
Visual Studio Blog
雷峰网
雷峰网
博客园_首页
Project Zero
Project Zero
美团技术团队
Google DeepMind News
Google DeepMind News
IT之家
IT之家
P
Palo Alto Networks Blog
有赞技术团队
有赞技术团队
S
Security @ Cisco Blogs
U
Unit 42
C
Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Security Archives - TechRepublic
Security Archives - TechRepublic
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
S
Schneier on Security
TaoSecurity Blog
TaoSecurity Blog
The Register - Security
The Register - Security
WordPress大学
WordPress大学
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
I
Intezer
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
Help Net Security
Help Net Security

博客园 - 落尘

.NET上传图片加文字和水印图片源码 - 落尘 - 博客园 ASP.NET下的多文件上传 ASP.NET 2.0 多文件上传小经验 文件的上传和下载 在ASP.NET程序中实现语音合成 .Net平台下开发中文语音应用程序 语音合成与识别技术在C#中的应用 如何防止ASP 木马在服务器上运行 用ASP实现在线压缩与解压缩 asp对象化之:基于adodb.stream的文件操作类 js鼠标及对象坐标控制属性 NET中各种数据库连接大全 几个ASP.NET技巧 设计ASP.NET应用程序的七大绝招 ASP.NET中如何调用存储过程 如何用C#把Doc文档转换成rtf格式 单点登陆 硬盘双击无法打开是咋回事 Asp.net直接保存文件到客户端
Asp.net cache 简述
落尘 · 2006-11-30 · via 博客园 - 落尘

Asp.net支持三种类型的cache
  
  想写一个技术快速概述,可能写得太多了。技术概略的目的是以最快最简单的方式描述出技术要点,也是我希望的最有效率的知识传播方式。
  
  
  1. 页面/控件cache
  
  2. 应用程序级cache
  
  3. 浏览器客户端cache
  
  
  从实现方式来看,页面/控件cache和应用程序级cache都是存放在服务器内存里面的,随着内存的紧张程度,这些内容有可能在失效之前被提前删除。(cache的特性决定这些内容是可以放心得删除掉的)。浏览器客户端的cache是存放在客户端浏览器的cache里面 ,比如IE的临时文件夹就是起的cache的作用。每次用户请求一个页面的时候,浏览器会先从cache里面去查找一下有没有符合要求的还没有过期的cache内容,如果有的话就从cache里面直接读取跳过网络传输。
  
  
  
  下面演示一下在Asp.net里面具体的写法:
  
  1. 页面/控件cache可以申明在aspx,ascx文件里面,也可以在code behind里面作出申明。
  
  <%@ OutputCache Duration="#ofseconds"
  
   Location="Any | Client | Downstream | Server | None |
  
   ServerAndClient "
  
   Shared="True | False"
  
   VaryByControl="controlname"
  
   VaryByCustom="browser | customstring"
  
   VaryByHeader="headers"
  
   VaryByParam="parametername"
  
   CacheProfile="cache profile name | ''"
  
   NoStore="true | false"
  
   SqlDependency="database/table name pair | CommandNotification"
  
  %>
  
  主要的参数是:
  
  Duration: cache有效的时间,单位秒
  
  Shared:只对控件有效,在控件可以同时应用与多个页面的时候,多个页面是否可以共享这一个cache而不用每个页面维护自己对这个控件的cache。
  
  VaryByControl:cache随控件的ID变化
  
  VaryByCustom:cache随用户自定义的一个变量来变化,该变量是在这里指定,然后应该在Global.ascx里面实现:
  
  public override string GetVaryByCustomString (
  
  HttpContext context,
  
  string custom
  
  )
  
  该声明的custom参数就是在OutPutcache里面申明的变量。通过在这个函数里面对不同的custom参数返回不同的字符串值来表示不同的cache内容。
  
  VaryByHeader, VaryByParam,CacheProfile也是设置不同的cache版本的。
  
  NoStore表示不允许把cache的内容写到内存以外其它的存储设备上,这是对安全性比较高的内容的需要。
  
  SqlDependency是和数据库相关的。
  
  
  2. 应用程序级cache
  
  只可以在code behind里面获得,特点是可以实现自己需要的任何cache逻辑。
  
  可以通过Page.Cache获得,类的名字是System.Web.Caching.Cache
  
  
  3. 浏览器客户端cache
  
  只可以在codebehind里面获得,可以通过Response.Cache来指定,这是一个HttpCachePolicy对象。
  
  
  
  另外: 可以指定一个TimeSpan作为cache的时间,不用每次来折算到秒。
  
   public TimeSpan(long ticks);
  
   public TimeSpan(int hours, int minutes, int seconds);
  
   public TimeSpan(int days, int hours, int minutes, int seconds);
  
   public TimeSpan(int days, int hours, int minutes, int seconds, int milliseconds);
  
  如果要cache保留一个小时1分1秒,可以直接
  
  new TimeSpan(1,1,1)
  
  而不用先计算
  
  1小时1分1秒=3600+60+1=3661秒,然后在传入3661作为有效期。

posted on 2006-11-30 08:55  落尘  阅读(672)  评论()    收藏  举报