如何在 .ashx 处理程序上使用输出缓存 [英] How to use output caching on .ashx handler

查看:28
本文介绍了如何在 .ashx 处理程序上使用输出缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将输出缓存与 .ashx 处理程序一起使用?在这种情况下,我正在进行一些繁重的图像处理,并希望将处理程序缓存一分钟左右.

How can I use output caching with a .ashx handler? In this case I'm doing some heavy image processing and would like the handler to be cached for a minute or so.

另外,有没有人对如何防止狗打狗有任何建议?

Also, does anyone have any recommendations on how to prevent dogpiling?

推荐答案

有一些很好的资源,但你想缓存你处理的服务器端和客户端.

There are some good sources but you want to cache you processing server side and client-side.

添加 HTTP 标头应该有助于客户端缓存

Adding HTTP headers should help in the client side caching

这里有一些响应头开始......

here are some Response headers to get started on..

您可以花费数小时调整它们,直到获得所需的性能

You can spend hours tweaking them until you get the desired performance

//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);

至于服务器端缓存,这是一个不同的怪物......而且有很多缓存资源......

As for server side caching that is a different monster... and there are plenty of caching resources out there...

这篇关于如何在 .ashx 处理程序上使用输出缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆