asp.net - 如何在 .ashx 处理程序上使用输出缓存

标签 asp.net caching ashx

如何将输出缓存与 .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/

相关文章:

zend-framework - 使用Varnish/ESI和Zend框架的缓存和页面 View

java - 在java中同时使多个worker的缓存无效而不影响性能

c# - 无法在 Firefox 中读取 ashx 中的 session 变量值?

jquery - 将 json 数组发送到 ashx 处理程序

asp.net - HTTP 错误 403.14 - 禁止在 Windows 7 上使用 visual studio 12 创建 Web 服务

c# - web.config中的Processmodel配置

asp.net - 如何使用 Fiddler 编辑 HTTP 请求

c# - 序列化属性的内容,但不序列化属性名称?

javascript - 单击后退按钮时防止从缓存中加载 Safari

javascript - 如何将 .ashx 文件中的值返回到变量中的 javascript