将用户控件输出缓存到内存以外的其他位置

发布于 2024-12-28 10:28:08 字数 140 浏览 2 评论 0原文

我已经实现了一个基于磁盘的缓存,并且还希望使其能够输出缓存用户控件。我读过,我不能将基于磁盘的输出缓存提供程序用于用户控件,而只能用于输出缓存整个页面。

是否可以以其他方式将用户控件输出缓存到磁盘或其他存储类型(db)?

谢谢 托马斯

I have implemented a diskbased cache and would also like to enable it to outputcache usercontrols as well. I have read that I cannot use the diskbased outputcache provider for usercontrols but only to outputcache entire pages.

Is it possible to outputcache the usercontrol to disk in some other way or to some other storagetype (db) ?

thanks
Thomas

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

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

发布评论

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

评论(1

燕归巢 2025-01-04 10:28:08

ASP.Net 4.0 添加了输出缓存可扩展性。您可以通过创建输出缓存提供程序来实现此目的。用 Scott Gu 的话说,

输出缓存提供程序可以使用任何存储机制来保存输出缓存内容。这使得可以轻松创建使用任何持久性机制存储缓存内容的输出缓存提供程序 - 包括本地或远程磁盘、数据库、云存储和分布式缓存引擎(如 memcached 或 Velocity)。

您可以通过子类化来创建输出缓存提供程序
OutputCacheProvider 基类。

创建缓存提供程序后,您可以在 web.config 文件中注册它:

<caching>
  <outputCache defaultProvider="MyCustomCacheProvider">
    <providers>
      <add name="MyCustomCacheProvider" type="CustomCacheProvider" />
      </providers>
    </outputCache>
</caching>

当您将 OutputCache 指令放在用户控件的 ascx 页面上时:

<%@ OutputCache Duration="120" VaryByParam="None" %>

您应该能够为您的用户控件使用此自定义缓存提供程序。

有关详细信息,请参阅 Scott Gu 的优秀博客文章

ASP.Net 4.0 added output cache extensibility. You do this by creating an output cache provider. In the words of Scott Gu,

Output-cache providers can use any storage mechanism to persist output cached content. This makes it possible to easily create output-cache providers that store the cached content using any persistence mechanism – including local or remote disks, databases, cloud storage, and distributed cache engines (like memcached or velocity).

You create an output cache provider by subclassing the
OutputCacheProvider base class.

Once you have created the cache provider, you can register it in your web.config file:

<caching>
  <outputCache defaultProvider="MyCustomCacheProvider">
    <providers>
      <add name="MyCustomCacheProvider" type="CustomCacheProvider" />
      </providers>
    </outputCache>
</caching>

When you put an OutputCache directive on your user control's ascx page:

<%@ OutputCache Duration="120" VaryByParam="None" %>

you should be able to use this custom cache provider for your user control.

For more information, see Scott Gu's excellent blog post.

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