<%@ OutputCache Duration="60" VaryByParam="none" %>
none 表示單一版本。| 屬性 | 說明 |
|---|---|
| VaryByControl | 依指定控件值變化快取 (如 VaryByControl="DropDownList1") |
| VaryByCustom | 自訂快取變異邏輯 (需覆寫 GetVaryByCustomString) |
| CacheProfile | 引用 Web.config 定義的快取設定檔 |
| Location | 快取位置 (Any/Client/Downstream/Server/None) |
| NoStore | true 時不儲存任何快取 |
| SqlDependency | SQL 快取相依性 |
<system.web>
<caching>
<outputCacheSettings>
<outputCacheProfiles>
<add name="CacheProfile1" duration="60" varyByParam="none" />
</outputCacheProfiles>
</outputCacheSettings>
</caching>
</system.web>
頁面引用:<%@ OutputCache CacheProfile="CacheProfile1" %>
Response.Cache.SetExpires(DateTime.Now.AddMinutes(5));
Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.VaryByParams["id"] = true;
VaryByCustom 區分使用者)。