我的網站上有一個菜單,根據用戶是否登錄進行更改。通過瀏覽器緩存,菜單在任何一種狀態下都會「卡住」,並且會讓用戶感到困惑。是否可以通過代碼清理瀏覽器緩存?
他們會登錄,但菜單不會更新,因爲它仍然處於未認證狀態,反之亦然。
這是如何處理的?我們可以從我們的代碼刷新用戶的瀏覽器緩存嗎?或者我只是不允許瀏覽器緩存? (寧願使用它,速度非常好)。
更新
下面是如何設置的客戶端,瀏覽器緩存在我的asp.net MVC 2應用程序:
public class CacheFilterAttribute : ActionFilterAttribute {
/// <summary>
/// Gets or sets the cache duration in seconds. The default is 10 seconds.
/// </summary>
/// <value>The cache duration in seconds.</value>
public int Duration { get; set; }
public CacheFilterAttribute() { Duration = 10; }
public override void OnActionExecuted(ActionExecutedContext filterContext) {
if (Duration <= 0) return;
var cache = filterContext.HttpContext.Response.Cache;
var cacheDuration = TimeSpan.FromSeconds(Duration);
cache.SetCacheability(HttpCacheability.Public);
cache.SetExpires(DateTime.Now.Add(cacheDuration));
cache.SetMaxAge(cacheDuration);
cache.AppendCacheExtension("must-revalidate, proxy-revalidate");
}
}
,然後應用[CachFilter(持續時間= 60)],以我的行動。 (注意,我從Kazi Manzur Rashid's Blog得到了上面的代碼
謝謝,我會盡快覈實這一點。如果它幫助我,我會報告。非常感激。 – Chaddeus 2010-09-19 14:17:01
優雅的解決方案和完美的結果!你救我!謝謝! – 2016-02-25 18:00:47