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