如何在服务器端缓存ASP.NET自定义HttpHandler响应

Joe*_*oel 5 asp.net caching httphandler

我的ASP.NET应用程序中有一个自定义的HttpHandler,它基本上构建并返回一个javascript对象.我没有服务器端缓存的经验,而且我的(可能无能的)谷歌搜索没有返回任何基本的东西来让我开始.

任何人都可以提供一个非常简单的示例,让我了解如何从自定义HttpHandler访问和使用服务器端缓存,或者,留下一些链接让我开始?非常感谢.

附加信息:我在IIS 6上,我的代码隐藏在C#中(尽管VB示例也可以).

Ray*_*Ray 4

非常简单的示例可以帮助您入门,无需锁定或错误处理:

public void ProcessRequest(HttpContext context) {
  MyObject thing = context.Cache["object_name"];
  if (thing == null) {
    thing = new MyObject();
    context.Cache["object_name"] = thing;
  }

  // use thing here to process request
}
Run Code Online (Sandbox Code Playgroud)