我创建了一个ashx文件,用于在运行时生成图像缩略图。我希望在第一次调用后将这些图像缓存到客户端。
URL:
~/image.ashx?dir=user&w=25&h=25&force=yes&img=matt.jpg
代码背景:
public void ProcessRequest (HttpContext context) {
TimeSpan refresh = new TimeSpan(0, 15, 0);
context.Response.Cache.SetExpires(DateTime.Now.Add(refresh));
context.Response.Cache.SetMaxAge(refresh);
context.Response.Cache.SetCacheability(HttpCacheability.Server);
context.Response.CacheControl = HttpCacheability.Public.ToString();
context.Response.Cache.SetValidUntilExpires(true);
string dir = context.Request.QueryString["dir"];
string img = context.Request.QueryString["img"];
bool force = context.Request.QueryString["force"] == "yes";
double w = 0;
double h = 0;
...
context.Response.ContentType = "image/jpeg";
thumb.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
使用Chrome的开发工具,我可以看到以下响应头:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 26 Sep 2011 19:17:31 GMT
X-AspNet-Version: 4.0.30319
Set-Cookie: .ASPXAUTH=...; path=/; HttpOnly
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: image/jpeg
Content-Length: 902
Connection: Close
有人能告诉我为什么这个URL在多次调用时没有缓存吗?非常感谢任何建议。