views:

351

answers:

2

I have written an HttpModule that accepts the request, processes it (via a database lookup), and outputs results (html) back to the response. (Note that the HttpModule actually ends the request after it is done, so there is no normal ASP.NET processing of the request.)

As the database lookup can be expensive/time-consuming, I would like to store the results in-memory so that subsequent (identical) requests can be served the same content without going to the database.

Where can I store (in-memory) data so that it is available for subsequent invocations of the HttpModule?

+2  A: 

You could store it in the Application.Cache, the result would be available Application wide then. Be sure to check for "new data" every now and then if necessary.

Colin
Even better = create cache dependency.
Robert Koritnik
Just wanted to edit my answer. Beat me to it. Since ASP.NET 2.0 and SQL 2005 it is possible to create a sort of "push" dependendecy for data.
Colin
A: 

How is response size compared to your data fetched from db? What about rendering once you have that data in memory? If rendering is not an issue, I would just cache the data and render it on each request. If rendering takes lots of cpu, then you should cache the full response and directly serve it from cache.