相关疑难解决方法(0)

如何以编程方式清除控制器操作方法的outputcache

如果控制器操作在操作上指定了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页面.

也许我只是手动插入的输出RenderToStringHttpContext.Cache,而是如果我不明白这一个.

更新

请注意,OutputCache是​​VaryByParam,测试出硬编码路径"/ controller/action"实际上并没有清除outputcache,所以看起来它必须匹配"/ controller/action/param1/param2".

这意味着我可能不得不恢复到对象级缓存并手动缓存输出RenderToString():(

asp.net asp.net-mvc

62
推荐指数
3
解决办法
4万
查看次数

有什么办法清除/刷新/删除OutputCache?

我在我的webuser控件(.ascx)上使用OutputCache

<%@ OutputCache Duration="1000" VaryByParam="none" %>
Run Code Online (Sandbox Code Playgroud)

我想在接下来的1000秒内保留缓存,但是当我的网站上的特定页面被加载时,我想删除/刷新/刷新缓存.就像,我想在加载MyPage.aspx时清除缓存.我可以在程序上刷新缓存吗?

它只有一个页面是缓存,因此没有用于刷新缓存的paramatrized版本.

感谢您的帮助.

asp.net caching

28
推荐指数
5
解决办法
2万
查看次数

如何清除HttpWebRequest的缓存

我正在开发一个专有的库,我遇到了缓存的一些问题HttpWebRequest.该库使用与下面相同的代码来发出请求:

var request = WebRequest.Create("http://example.com/") as HttpWebRequest;

request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.CacheIfAvailable);
Run Code Online (Sandbox Code Playgroud)

尽管每个响应都不同,但外部资源不会禁止缓存.因此,我每次都得到相同的回应.

有没有办法清除HttpWebRequest缓存的内容?正确的解决方案是修复外部源或者更改缓存策略,但两者都不可能 - 因此问题.

清除高速缓存可能具有各种影响,因此优选地,解决方案是基于每个资源使高速缓存无效.

.net caching httpwebrequest

27
推荐指数
2
解决办法
3万
查看次数

缓存,直到ASP.NET MVC和实体框架4.1中的数据更改

我目前在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

7
推荐指数
1
解决办法
2468
查看次数

你能否强制删除asp.net-mvc中的(page和partialView)OutputCache

我想要一个简单的方法来清除我的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)

c# asp.net-mvc outputcache output-caching

6
推荐指数
1
解决办法
4216
查看次数

如何在ChildAction上删除OutputCache?

我正在尝试利用.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中删除缓存项?

asp.net-mvc outputcache asp.net-mvc-3

5
推荐指数
1
解决办法
2125
查看次数