如何清除在ASP MVC指定控制器高速缓存? [英] How to clear cache in specified controller in asp mvc?
本文介绍了如何清除在ASP MVC指定控制器高速缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
<一href="http://stackoverflow.com/questions/1167890/how-to-programmatically-clear-outputcache-for-controller-action-method">How以编程方式明确的OutputCache对控制器的操作方法
如何清除指定控制器高速缓存?
How to clear cache in specified controller?
我尝试使用了几种方法:
I try to use several approaches:
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()
{
////////...
}
来源:原来code
这篇关于如何清除在ASP MVC指定控制器高速缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文