使用 HttpModule 跨请求缓存

发布于 2024-07-25 20:32:23 字数 234 浏览 3 评论 0原文

我编写了一个 HttpModule,它接受请求、处理请求(通过数据库查找)并将结果 (html) 输出回响应。 (请注意,HttpModule 实际上会在完成后结束请求,因此不会对请求进行正常的 ASP.NET 处理。)

由于数据库查找可能会很昂贵/耗时,我想将结果存储在内存中以便后续(相同)请求可以提供相同的内容,而无需访问数据库。

我可以在哪里存储(内存中)数据,以便后续调用 HttpModule 时可用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谈下烟灰 2024-08-01 20:32:23

您可以将其存储在 Application.Cache 中,然后结果将在应用程序范围内可用。 如有必要,请务必时不时检查“新数据”。

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.

°如果伤别离去 2024-08-01 20:32:23

与从数据库获取的数据相比,响应大小如何? 一旦内存中有这些数据,渲染怎么样? 如果渲染不是问题,我只需缓存数据并在每个请求上渲染它。 如果渲染需要大量 CPU,那么您应该缓存完整的响应并直接从缓存中提供服务。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文