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

有些话、适合烂在心里 提交于 2019-12-14 01:01:54

问题


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).


回答1:


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
}


来源:https://stackoverflow.com/questions/2852462/how-to-server-side-cache-asp-net-custom-httphandler-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!