【问题标题】:Why are my images not cached although I configured OUTPUTCACHE?为什么我配置了 OUTPUTCHACHE 却没有缓存我的图像?
【发布时间】:2018-01-29 09:29:49
【问题描述】:

所以, 我试图为我的 MVC5 应用程序配置缓存以进行优化。尽管我将OutputCache 属性放在控制器操作方法上,但我看不到缓存的图像。 这是控制器动作:

[OutputCache(Duration = 60, Location = OutputCacheLocation.ServerAndClient, NoStore=true, VaryByParam = "resultid")]
public FileContentResult getPicture(string resultid)
{
   var actionLinks = db.ActionLinks.ToList();
   var actionLinkPic = actionLinks.FirstOrDefault(p => p.Id == resultid);
   if (actionLinks != null)
   {
      return File(actionLinkPic.TPicture, actionLinkPic.TPictureMimeType);
   }
   else
   {
      return null;
   }
}

这是firefox中的网络响应:

网络响应:

【问题讨论】:

  • 尝试删除NoStore=true
  • 那会永久保存那些图片,我不想要那个

标签: asp.net-mvc caching outputcache


【解决方案1】:

你有NoStore=true

NoStore 属性完全禁用缓存 - 它通常用于禁用 GET 请求(默认缓存)的缓存。

改成NoStore=false

不幸的是,OutputCacheAttribute 的文档很少,因此在一定程度上您将不得不尝试这些选项,看看会发生什么。

【讨论】:

  • 仍然没有被NoStore=false缓存,可能是什么问题?
  • 我需要在应用程序web.config中添加输出缓存配置吗?
  • 浏览器可以在开发者窗口的代码和设置中禁用缓存。请您分享发出 getPicture 请求的 Javascript/HTML。
  • <img class='activity-picture' src="@Url.Action("getPicture", "ActionLinks", new { resultid = item.Id })" alt="@item.ActionText" /> 在这里。
  • 让我补充一点,我的应用程序 Web 配置中没有任何关于输出缓存的单行代码。我也在本地测试这个应用程序
猜你喜欢
  • 1970-01-01
  • 2011-09-18
  • 1970-01-01
  • 1970-01-01
  • 2016-09-28
  • 1970-01-01
  • 2021-05-01
  • 2011-05-17
  • 1970-01-01
相关资源
最近更新 更多