负载页新鲜,而不是从缓存 [英] load page freshly and not from cache

查看:118
本文介绍了负载页新鲜,而不是从缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法,我可以强制页不从缓存中加载?每次页面加载它是从服务器加载。
我使用asp.net MVC 3。

Is there way I can force 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.

这篇关于负载页新鲜,而不是从缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆