![]() |
MSDN上缓存概述:http://msdn2.microsoft.com/zh-cn/library/726btaeh%28VS.80%29.aspx
一、页输出缓存 ![]() <%@ OutputCache Duration="" VaryByParam="" VaryByControl="" VaryByHeader="" VaryByCustom="" CacheProfile="" Location="" %>
![]() <%@ OutputCache Duration="60" VaryByParam="City" %>
![]() <%@ OutputCache Duration="60" VaryByParam="None" VaryByHeader="Accept-Language" %>
![]() <%@ OutputCache Duration="10" VaryByParam="None" VaryByCustom="browser" %>
![]() <%@ OutputCache Duration="10" VaryByParam="None" VaryByCustom="minorversion" %>
![]() <!-- caching section group --> <caching> <outputCacheSettings> <outputCacheProfiles> <add name="AppCache1" enabled="true" duration="60"/> </outputCacheProfiles> </outputCacheSettings> </caching>
![]() <%@ OutputCache CacheProfile="AppCache1" VaryByParam="None" %>
![]() Response.Cache.SetExpires(DateTime.Now.AddSeconds(60)); //设置缓存过期时间 Response.Cache.SetCacheability(HttpCacheability.Public); //设置页的可缓存性 Response.Cache.SetValidUntilExpires(true); //缓存忽略 Cache-Control 无效标头
![]() protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(1.0)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.VaryByParams["Zip"] = true; }
![]() protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(1.0)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.VaryByHeaders["Accept-Language"] = true; }
![]() protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(1.0)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.SetVaryByCustom("browser"); }
![]() protected void Page_Load(object sender, EventArgs e) { Response.Cache.SetExpires(DateTime.Now.AddMinutes(1.0)); Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetValidUntilExpires(true); Response.Cache.SetVaryByCustom("minorversion"); }
![]() <asp:Label ID="Label1" runat="server" Text="Label" Width="276px"></asp:Label> <br /> <asp:Substitution ID="Substitution1" runat="server" MethodName="NoCache" />
![]() protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); } protected static string NoCache(HttpContext context) { return DateTime.Now.ToString(); }
![]() Cache.Insert("CacheItem2", "Cached Item 2");
![]() string[] dependencies = { "CacheItem2" }; Cache.Insert("CacheItem3", "Cached Item 3",new System.Web.Caching.CacheDependency(null, dependencies));
![]() Cache.Insert("CacheItem6", "Cached Item 6",null, DateTime.Now.AddMinutes(1d), System.Web.Caching.Cache.NoSlidingExpiration);
![]() Cache.Insert("CacheItem8", "Cached Item 8", null, System.Web.Caching.Cache.NoAbsoluteExpiration, System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.High, null);
![]() string cachedString; cachedString = (string)Cache["CacheItem"]; if (cachedString == null) { cachedString = "Www.Mzwu.Com"; Cache.Insert("CacheItem", cachedString); }
![]() Cache.Remove("MyData1"); |