Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)qq
published in(发表于) 2014/7/9 1:40:15
在asp.net2.0页面部分缓存中使用PartialCachingAttribu

在asp.net2.0页面部分缓存中使用PartialCachingAttribu

使用PartialCachingAttribute类

使用PartialCachingAttribute类定义Web窗体用户控件,用于设置有关控件缓存的配置内容。本节主要讲解PartialCachingAttribute类的6个常用属性和4种类构造函数。6个常用属性是Duration、Shared、SqlDependency、VaryByControl、VaryByCustom和VaryByParam。与19.2节中的@ OutputCache指令设置的6个属性完全相同,但所使用的方式不同。PartialCaching Attribute类中的构造函数和常用属性及说明如表1和表2所示。



表1 PartialCachingAttribute类的构造函数及说明



表2 PartialCachingAttribute类的常用属性及说明

以上介绍了PartialCachingAttribute类的6个属性和4种构造函数。下面通过一个典型示例说明该类的具体应用方法。

本示例使用PartialCachingAttribute类设置用户控件(WebUserControl.ascx文件)的缓存有效期时间是20s。

使用PartialCachingAttribute类实现设置用户控件缓存,必须在用户控件类声明前设置“[PartialCaching(20)]”,代码如下:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

[PartialCaching(20)] //设置用户控件的缓存时间为20s

public partial class WebUserControl : System.Web.UI.UserControl

{

}

以上代码设置了缓存有效时间为20s。这与在WebUserControl.ascx文件顶部设置@ Output Cache指令的Duration属性值为20是完全一致的。




If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759