Page Output Caching
You will now add a new page to your project that supports Page Output Caching.
1. Add a new Web Form to your project, naming it "PageOutputCaching.aspx". In the Add New Item dialog make sure to check Place code in separate file and Select Master Page, selecting MasterPage.master.
2. Open Web.sitemap and add another siteMapNode child element //子元素so that "Page Output Caching" appears in the navigation menu.

3. Click the PageOutputCaching.aspx tab and then click Design. Select the Content control, press F4, and then change the (ID) property to "bodyContent". In the Content control type "Page Output Caching", highlight //高亮显示it, and then from the Block Format toolbar menu, select Heading 2 <H2>. Finally, in the Content control type "Timestamp: "//时间戳, and then drag a Label control to the design surface, changing its ID property to "timestampLabel".

4. Double-click //双击anywhere on the gray area//灰色区域 to add a Page Load event handler//页面载入事件处理器. To the handler add the following code, which sets the Label control's Text property to display the date and time that the page loaded:
| C# | VB | |
timestampLabel.Text = DateTime.Now.ToString();
|
||
5. Click the PageOutputCaching.aspx tab and then click Source. Add the following OutputCache directive//指令 below the Page directive//在页面指令的下面, effectively caching //有效缓存the page's contents for ten seconds: <%@ OutputCache VaryByParam="none" Duration="10" %>.
6. Press F5 to run the application. When the page loads, note the time and then press F5 continually until you see the time change approximately//近似地,大约 10 seconds later<十秒之内按F5时缓存时间不变,只有过了十秒时间才会变为新的时间>.
As you can see, cached page contents were served until the cache expired, at which time new page contents were served.
浙公网安备 33010602011771号