开发者

load page freshly and not from cache

开发者 https://www.devze.com 2023-03-06 00:39 出处:网络
Is there way I can force 开发者_JAVA技巧page not to load from cache? Everytime page is loaded it is loaded from server.

Is there way I can force 开发者_JAVA技巧page not to load from cache? Everytime page is loaded it is loaded from server. I'm using asp.net MVC 3.


You could use a custom no cache action filter:

public class NoCacheAttribute : ActionFilterAttribute
{  
    public override void OnResultExecuting(ResultExecutingContext filterContext)
    {
        var cache = filterContext.HttpContext.Response.Cache;
        cache.SetExpires(DateTime.UtcNow.AddDays(-1));
        cache.SetValidUntilExpires(false);
        cache.SetRevalidation(HttpCacheRevalidation.AllCaches);
        cache.SetCacheability(HttpCacheability.NoCache);
        cache.SetNoStore();
        base.OnResultExecuting(filterContext);
    }
}

Then decorate any controller/action with this attribute that you don't want to be cached by client browsers.

0

精彩评论

暂无评论...
验证码 换一张
取 消