2011-08-25 23 views
0

我有幾個usercontrols,我想有一個不同的輸出緩存超時。不同的輸出緩存超時爲不同的用戶控件

我曾嘗試以下,但沒有成功:

  • 集cacheprofile(顯然可以只在aspx頁面來完成)。
  • 不要在代碼隱藏以下內容:

    Response.Cache.SetExpires(DateTime.Now.AddDays(OutputCaching.QuickTimeout))

    Response.Cache.SetCacheability(HttpCacheability.Public)

    響應.Cache.SetValidUntilExpires(真);

    Response.Cache.VaryByParams.IgnoreParams = true;

顯然只有<%@ OutputCache Duration="6000" VaryByParam="" %>的作品,而不是有沒有辦法把時間從config-或文件的AppSettings?

+1

簡短的回答是否定的。該文檔說,cacheprofile在usercontrols中不受支持 –

回答

0

技術上有可能基於該備註this article但認爲的

HttpCacheability.Server = @的OutputCache

代替

HttpCacheability.Public

這裏是HttpCacheability的文檔,這將幫助你選擇正確的選擇吧。

而且我認爲,如果你把你的代碼放在Page_Init或Page_PreInit這樣這將是最好的:

Private Sub Page_Init(sender As Object, e As System.EventArgs) Handles Me.Init 
    Me.Response.Cache.SetCacheability(HttpCacheability.Server) 
    Me.Response.Cache.SetExpires(Date.Now.AddMinutes(10)) 
    Me.Response.Cache.SetValidUntilExpires(True) 
    Me.Response.Cache.VaryByParams.IgnoreParams = True 
End Sub 

問候,

相關問題