Using Output Cache

Using Output Cache

 

Output page caching is an ASP.NET feature that increases the performance of your web application by caching the HTML content generated from dynamic pages or controls. In other words, a page or user control that has output caching enabled is only executed the first time it is requested. On subsequent requests, the page or control is served directly from the cache, instead of being executed again.

 

The drawback with output caching is that if the information in the database changes in the meanwhile, your page will display outdated information. Also, enabling output caching, although it saves server-processing power, consumes server memory, and should be used with caution.

 

You can enable output page caching for a Web Form or Web User Control using the OutputCache page directive, which has a number of optional parameters:

<%@ OutputCache

Duration="#ofseconds"

Location="Any | Client | Downstream | Server | None"

Shared="True | False"

VaryByControl="controlname"

VaryByCustom="browser | customstring"

VaryByHeader="headers"

VaryByParam="parametername" %>

 

Explanation:

Shared: Applies only to user controls, and specifies whether the output of the user

control should be cached once for all the pages that include the control, or if multiple

versions of the control should be cached for each page that contains it.

 

VaryByParam: Varies the output cache based on the values of the parameters passed to

the server, which include the query string parameters.

 

For example:

<%@ OutputCache Duration="1000"

VaryByParam="DepartmentIndex;CategoryIndex;Search;AllWords;PageNumber;

ProductsOnPage" %>

 

Although implementing output page caching saves the database, it occupies web server memory.

 

For this reason, I recommend that implementing output caching for some static web user controls, such as Page Header, Page Footer, and so on.

 

Note: The above content is excerpted from ASP.NET 2.0 ecommerce in C# 2005 From Novice to Professional – Apress.

 

 

posted @   Rickie  阅读(894)  评论(1编辑  收藏  举报
编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示