如何将输出缓存与 .ashx 处理程序一起使用?在这种情况下,我正在进行一些繁重的图像处理,并希望将处理程序缓存一分钟左右。
另外,有没有人有任何关于如何防止dogpiling的建议?
最佳答案
有一些很好的来源,但您想缓存处理服务器端和客户端。
添加 HTTP header 应该有助于客户端缓存
这里有一些 Response header 可以开始使用..
您可以花数小时调整它们,直到获得所需的性能
//Adds document content type
context.Response.ContentType = currentDocument.MimeType;
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.Cache.SetExpires(DateTime.Now.AddMinutes(10));
context.Response.Cache.SetMaxAge(new TimeSpan(0,10,0));
context.Response.AddHeader("Last-Modified", currentDocument.LastUpdated.ToLongDateString());
// Send back the file content
context.Response.BinaryWrite(currentDocument.Document);
至于服务器端缓存,这是一个不同的怪物......那里有很多缓存资源......
关于asp.net - 如何在 .ashx 处理程序上使用输出缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1109768/