如何清除asp mvc中指定控制器中的缓存? [英] How to clear cache in specified controller in asp mvc?
本文介绍了如何清除asp mvc中指定控制器中的缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
如何以编程方式清除控制器操作方法的输出缓存
如何清除指定控制器中的缓存?
How to clear cache in specified controller?
我尝试使用多种方法:
Response.RemoveOutputCacheItem();
Response.Cache.SetExpires(DateTime.Now);
没有任何效果,它不起作用.:(可能存在任何方式来获取控制器缓存中的所有键并明确删除它们?我应该在哪个重写的方法中执行清除缓存?以及如何做到这一点?
There is no any effect, it not work. :( May be exists any way to get all keys in controller cache and remove they explicitly? And in which overridden method i should perform clear cache? and how to do that?
有什么想法吗?
推荐答案
试试这个:
把它放在你的模型上:
public class NoCache : 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);
}
}
并在您的特定控制器上:例如:
and on your specific controller: e.g:
[NoCache]
[Authorize]
public ActionResult Home()
{
////////...
}
来源:原始代码
这篇关于如何清除asp mvc中指定控制器中的缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文