如果控制器操作在操作上指定了OutputCache属性,是否有任何方法可以清除输出缓存而无需重新启动IIS?
[OutputCache (Duration=3600,VaryByParam="param1;param2")]
public string AjaxHtmlOutputMethod(string param1, string param2)
{
var someModel = SomeModel.Find( param1, param2 );
//set up ViewData
...
return RenderToString( "ViewName", someModel );
}
Run Code Online (Sandbox Code Playgroud)
我正在考虑使用HttpResponse.RemoveOutputCacheItem(string path)
它来清除它,但是我很难弄清楚应该将它映射到action方法的路径.我将再次尝试使用ViewName呈现的aspx页面.
也许我只是手动插入的输出RenderToString
入HttpContext.Cache
,而是如果我不明白这一个.
更新
请注意,OutputCache是VaryByParam,测试出硬编码路径"/ controller/action"实际上并没有清除outputcache,所以看起来它必须匹配"/ controller/action/param1/param2".
这意味着我可能不得不恢复到对象级缓存并手动缓存输出RenderToString()
:(
我在我的webuser控件(.ascx)上使用OutputCache
<%@ OutputCache Duration="1000" VaryByParam="none" %>
Run Code Online (Sandbox Code Playgroud)
我想在接下来的1000秒内保留缓存,但是当我的网站上的特定页面被加载时,我想删除/刷新/刷新缓存.就像,我想在加载MyPage.aspx时清除缓存.我可以在程序上刷新缓存吗?
它只有一个页面是缓存,因此没有用于刷新缓存的paramatrized版本.
感谢您的帮助.
我正在开发一个专有的库,我遇到了缓存的一些问题HttpWebRequest
.该库使用与下面相同的代码来发出请求:
var request = WebRequest.Create("http://example.com/") as HttpWebRequest;
request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
Run Code Online (Sandbox Code Playgroud)
尽管每个响应都不同,但外部资源不会禁止缓存.因此,我每次都得到相同的回应.
有没有办法清除HttpWebRequest
缓存的内容?正确的解决方案是修复外部源或者更改缓存策略,但两者都不可能 - 因此问题.
清除高速缓存可能具有各种影响,因此优选地,解决方案是基于每个资源使高速缓存无效.
我目前在ASP.NET MVC 3应用程序中使用存储库模式.
我使用OutputCache通过使用类似于此的数据注释装饰我的控制器方法来减轻数据库的负载:
[OutputCache(Duration = 3600, VaryByParam = "userName")]
Run Code Online (Sandbox Code Playgroud)
最终,我想要实现的是一种缓存级别,数据被缓存直到它被更新(即它发生变化).我正在使用Entity Framework 4.1 for ORM.
使用我选择的堆栈建议的方法是什么?
asp.net-mvc caching outputcache entity-framework-4.1 asp.net-mvc-3
我想要一个简单的方法来清除我的asp.net-mvc网站上的缓存页面.
我有昂贵的数据库操作,所以我经常使用输出缓存来使网站运行得更快.我的代码看起来像这样:
[OutputCache(Duration = 30000)]
public ActionResult Index()
{
return View();
}
[OutputCache(Duration = 30000, VaryByParam = "*")]
public ActionResult GetData(MyParams myParams)
{
return PartialView("MyView", GetVM(myParams));
}
Run Code Online (Sandbox Code Playgroud)
当我想明确清除此缓存(无论现有的缓存持续时间)时,有一些时候(当出现问题时)
无论如何,有完整和部分页面Outputcaching删除缓存页面并运行完整的代码?
注意:我看到这个问题已经在这里围绕asp.net一般问过,但我没看到asp.net-mvc特定的解决方案
我试过这个,但它似乎不起作用:
public ActionResult ClearCache()
{
this.HttpContext.Response.RemoveOutputCacheItem("/MyController/Index.aspx");
this.HttpContext.Response.RemoveOutputCacheItem("/MyController/MyView.ascx");
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试利用.Net MVC 3中的甜甜圈缓存功能.对于我的主页,在我的家庭控制器中,我有:
public ActionResult Index()
{
return View();
}
[ChildActionOnly]
[OutputCache(Duration=3600)]
public ActionResult IndexMain()
{
return PartialView(ViewModelRepository.GetIndexViewModel());
}
Run Code Online (Sandbox Code Playgroud)
我的观点,我有:
<% Html.RenderAction("IndexMain");%>
Run Code Online (Sandbox Code Playgroud)
一切正常.但是,当数据发生变化时,我运行:
var urlToRemove = Url.Action("IndexMain", "Home");
Response.RemoveOutputCacheItem(urlToRemove);
Run Code Online (Sandbox Code Playgroud)
RemoveOutputCacheItem执行时没有错误,但ChildAction缓存未失效.有没有办法以编程方式从ChildAction中删除缓存项?