MVC4中的OutputCache有问题吗? [英] Problem with OutputCache in MVC4?

查看:96
本文介绍了MVC4中的OutputCache有问题吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用OutputCache在ActionMethod上缓存持续60秒的持续时间,后退项目列表。它运行正常,但问题是当我在列表中添加项目时,ActionMethod返回上一个列表,新项目未在列表中显示60秒。我如何克服这个问题?

I am using OutputCache to cache for duration like 60 sec on ActionMethod that retrun the list of item. It work fine, but the problem is when i add item in list then the ActionMethod return the previous list, the new item not shown in list for 60 sec. How i can overcome this problem?

推荐答案

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

        base.OnResultExecuting(filterContext);
    }
}


这篇关于MVC4中的OutputCache有问题吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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