緩衝 Output Cache

來源:互聯網
上載者:User
當一份asp.net網頁第一次被訪問,會被編譯成IL,接著是Native Code,而Native Code會緩衝成Page類,在下一次使用者請求同一頁面的時候直接供其使用。當asp.net初始檔案被更新,或者超出緩衝區的時間設定(Timeout),整份asp.net網頁會被重新編譯,並再一次置入Page類的緩衝區中。

一、逾時設定

<%@ OutputCache Duration="600"%>

二、指定絕對到期日
    假如要在10分鐘之後重新緩衝一次頁面,可以設定Response.Cache對象的兩個方法,SetExpires與SetCacheability,程式會自動更改HTTP標題。

Response.Cache.SetExpires(DateTime.Now.AddSeconds(600));
Response.Cache.SetCacheability(HttpCacheability.Public);

    以上兩個語句可以精簡地寫成這樣

Response.Expires="600";
Response.CacheControl="public";

三、指定相對到期日
    用來指定最後一次訪問後,多久逾時。
    舉例來說,某網站可能一天才更新一次,但訪問量動輒數萬,如果設定為第一次訪問後10分鐘失效,再緩衝一次,似乎沒什麼協助,因此改為最後一次被調用後多久才失效,也就是相對到期日。
    關鍵在於 Response.Cache 對象的 SetSlidingExpiration 屬性設定為 True

Response.Cache.SetExpires(DateTime.Now.AddSeconds(3600));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetSlidingExpiration(True);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.