1、使用@OutputCache指令
使用@OutputCache指令,能够实现对页面输出缓存的一般性能需求。@OutputCache指令在ASP.NET而或页中包含的用户控件的头部声明。
<%@ OutputCache CacheProfile=" " NoStore="True|False" Duration="#ofseconds" Shared="True|False" Location="Any | Client | Downsteam | Server | None | ServerandClient" SqlDependency="database /table name pair | CommandNotification " VaryByControl=" controlname" VaryByCustome="browser | customstring" VaryByHeader="headers" VaryByParam="parametername" %>
例子:<%@ OutputCache Duration="100" VaryByParam="none" %>
<%@ OutputCache Duration="100" VaryByParam="location;firstname" %>
2、使用页面输出缓存API
使用页面输出缓存API的常用方法有:SetExpires方法、SetLastModified方法、SetSlidingExpiration方法、SetOmitVaryStar方法和SetCacheablility方法。
例子:Response.Cache.SetExpires(DateTime.Now.AddSeconds(60));
Response.Cache.SetExpires(DateTime.Parse("6:00:00PM")); //绝对过期时间