2013-03-06 79 views
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); 

回答

0

我建議你在web.config中配置這個而不是。

<system.webServer> 

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

</system.webServer>