检查缓存图像代码

时间:2013-03-06 11:47:14

标签: c# asp.net-mvc caching

我有代码在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);

1 个答案:

答案 0 :(得分:0)

我建议你在web.config中配置它。

<system.webServer>

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

</system.webServer>