开发者

How to server-side cache ASP.NET custom HttpHandler response

开发者 https://www.devze.com 2022-12-31 14:48 出处:网络
I\'ve got a custom HttpHandler in my ASP.NET application, that basically builds and returns a javascript object.I have no experience with server-side caching, and my (possibly incompetent) google sear

I've got a custom HttpHandler in my ASP.NET application, that basically builds and returns a javascript object. I have no experience with server-side caching, and my (possibly incompetent) google searches aren't returning anything basic enough to get me started.

Could anyone provide a very simple example to give me an idea of how to access and use the server-side cache from a custom HttpHandler, or, leave some links to get me started? Thanks a lot.

Additional info: I'm on IIS开发者_如何学运维 6, and my code-behind is in C# (although a VB example would work as well).


Very simple example to get you started, without locking or error handling:

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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消