IIS 和 ASP.NET 缓存

发布于 2024-12-12 20:40:13 字数 335 浏览 0 评论 0原文

我创建了一个使用经典 ASP.NET 缓存的网站:

DataSet ds = new DataSet();
ds = (DataSet) Cache["MyDataSet"];

在 ASP.NET 代码中,我将持续时间设置为几个小时,但 IIS 会更早地重置缓存。
在 IIS 中,我可以在哪里手动设置 ASP.NET 缓存的持续时间?

我有足够的 RAM,具有满载的缓存和工作站点,我还有大约 1/3 的可用空间(总共 3GB,Web Server 2008R2)。

(我在缓存中进行了大量计算(几分钟),并且在工作期间我只更新缓存的一小部分)

I've created a web site that uses classic ASP.NET caching:

DataSet ds = new DataSet();
ds = (DataSet) Cache["MyDataSet"];

In ASP.NET code, I've set the duration for several hours, however IIS resets cache much earlier.
In IIS, where can I manually set the duration of ASP.NET caching?

I have enough RAM, with fully loaded cache and working sites I have about 1/3 free (3GBtotal, Web Server 2008R2).

(I have heavy calculations (several minutes) that are in cache, and during work I update only small parts of cache)

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

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

发布评论

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

评论(2

暗恋未遂 2024-12-19 20:40:14

为了测试您的元素何时自动从缓存中删除,您可以在发生这种情况时收到通知:ASP.NET 为此提供了 CacheItemRemovedCallback 委托。 Cache.Insert 语句具有重载,因此您可以编写类似的内容

Cache.Insert(
        "CacheItem",
        yourobject, 
        null,
        DateTime.Now.AddHours(3), 
        System.Web.Caching.Cache.NoSlidingExpiration
        CacheItemPriority.Default,
        new CacheItemRemovedCallback(ObjectRemovedCallback));

(不确定我是否 100% 正确),然后由业务对象中的 ObjectRemovedCallback 方法进行处理。检查http://msdn.microsoft.com/en-us/library/7kxdx246。 aspx 了解更多详细信息。您很有可能在这里找到缓存过早过期的原因。

In order to test when your element gets automatically removed from your cache, you can get notified when that happens: ASP.NET provides the CacheItemRemovedCallback delegate for that purpose. The Cache.Insert statement has an overload, so you can write something like

Cache.Insert(
        "CacheItem",
        yourobject, 
        null,
        DateTime.Now.AddHours(3), 
        System.Web.Caching.Cache.NoSlidingExpiration
        CacheItemPriority.Default,
        new CacheItemRemovedCallback(ObjectRemovedCallback));

(not sure if I got that 100% right) and then have that handled by a ObjectRemovedCallback method in a business object. Check http://msdn.microsoft.com/en-us/library/7kxdx246.aspx for more details. There is a good chance that you can find out the reason for your premature cache expiration here.

那伤。 2024-12-19 20:40:13

将对象添加到Cache时,可以指定过期策略(绝对、滑动过期)。

Cache.Insert("CacheItem", yourobject,
    null, DateTime.Now.AddHours(3), 
    System.Web.Caching.Cache.NoSlidingExpiration);

请参阅此处了解更多详细信息解释。

以下是对象可能从缓存中删除的一些原因:

由于以下原因之一,ASP.NET 可以从缓存中删除数据:

由于服务器上的内存不足,该过程称为清理。

因为缓存中的项目已经过期。

因为项目的依赖关系发生了变化。

为了帮助您管理缓存项目,ASP.NET 可以通知您的应用程序
当项目从缓存中删除时。

清理

清理是当内存不足时从缓存中删除项目的过程
是稀缺的。当某些项目在某些情况下未被访问时,项目将被删除
时间或当项目被添加到时被标记为低优先级
缓存。 ASP.NET 使用 CacheItemPriority 对象来确定
首先要清理哪些物品。有关详细信息,请参阅如何:添加
缓存中的项目。到期

除了清理之外,ASP.NET 还会自动从
过期时缓存。

When you add the object to the Cache, you can specify the expiration policy (absolute, sliding expiration).

Cache.Insert("CacheItem", yourobject,
    null, DateTime.Now.AddHours(3), 
    System.Web.Caching.Cache.NoSlidingExpiration);

See here for a more detailed explanation.

Here's some reasons why an object may be removed from Cache:

ASP.NET can remove data from the cache for one of these reasons:

Because memory on the server is low, a process known as scavenging.

Because the item in the cache has expired.

Because the item's dependency changes.

To help you manage cached items, ASP.NET can notify your application
when items are removed from the cache.

Scavenging

Scavenging is the process of deleting items from the cache when memory
is scarce. Items are removed when they have not been accessed in some
time or when items are marked as low priority when they are added to
the cache. ASP.NET uses the CacheItemPriority object to determine
which items to scavenge first. For more information, see How to: Add
Items to the Cache. Expiration

In addition to scavenging, ASP.NET automatically removes items from
the cache when they expire.

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