1

我有在 MVC 操作中缓存图像的代码,但我不明白什么是真正需要的,什么是多余的。你能检查一下并告诉我你的意见吗?

Response.Cache.SetCacheability(HttpCacheability.Public);
Response.Cache.SetExpires(DateTime.Now.AddSeconds(ApplicationSettings.CacheDuration));
Response.AppendHeader("Content-Length", imageContent.Length.ToString());
Response.Cache.VaryByParams.IgnoreParams = true;
Response.Cache.VaryByParams["*"] = true;
Response.Cache.SetValidUntilExpires(false);
Response.Cache.SetMaxAge(new TimeSpan(0, 0, ApplicationSettings.CacheDuration));
Response.AddHeader("content-disposition", string.Format("inline; filename={0}", fileName));

Response.OutputStream.Write(imageContent, 0, imageContent.Length);
Response.Flush();

return File(imageContent, contentType);
4

1 回答 1

0

我建议您改为在 web.config 中配置它。

<system.webServer>

  <staticContent>
    <clientCache cacheControlMode="UseExpires" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" />
   </staticContent>

</system.webServer>
于 2013-03-06T12:01:58.597 回答