我创建了一个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中的Dev工具,我可以看到以下响应头:
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对多个调用进行缓存吗?任何提示都将不胜感激。
发布于 2011-09-26 19:26:59
当然,这句话:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Server);应:
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);https://stackoverflow.com/questions/7560180
复制相似问题