【问题标题】:DonutOutputCache not working for an imageDonutOutputCache 不适用于图像
【发布时间】:2015-02-20 10:32:30
【问题描述】:

我有一个 ASP.NET MVC 控制器操作,如下所示:

[HttpGet]
[DonutOutputCache(CacheProfile = "banner")] 
public async Task<ActionResult> Banner(string name, string size = "lg")
{
    // snipped - work out which banner to show today.

    return File(thePathToSomeBannerImageFile, "image/jpeg");
}

配置文件如下:

<caching>
  <outputCacheSettings>
    <outputCacheProfiles>
      ...
      <add name="banner" duration="31536000" varyByParam="*" />
      ...
    </outputCacheProfiles>
  </outputCacheSettings>
</caching>

由于添加了DonutOutputCache,我用来渲染到浏览器的图像现在无法加载。我可以在 Fiddler 跟踪中看到一个较大的二进制文件正在进入浏览器,但我似乎无法让它呈现。

删除DonutOutputCache 会使图像再次出现。

我试过清除缓存等。有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc donut-caching


    【解决方案1】:

    啊,刚刚从这个链接弄明白了:Doesn't work w/ Files?

    基本上DonutOutputCache 在内部使用ContentResult,它仅适用于基于文本的内容。由于我在 FileResult 中返回了二进制响应,所以它搞砸了。幸运的是,它与内置的OutputCache 并排工作,所以我可以按如下方式修改我的操作,它可以按预期工作。我真的只需要DonutOutputCache 来处理我网站中基于文本的其他部分。我试图只使用一个缓存属性来统治它们,但我自己却绊倒了。

    [HttpGet]
    [OutputCache(CacheProfile = "banner")] 
    public async Task<ActionResult> Banner(string name, string size = "lg")
    {
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-15
      • 1970-01-01
      • 2012-07-28
      • 2021-06-18
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      相关资源
      最近更新 更多