When Does Asp.Net Remove Expired Cache Items?

前端 未结 2 850
北荒
北荒 2020-12-03 00:04

When you add an item to the System.Web.Caching.Cache with an absolute expiration date, as in the following example, how does Asp.Net behave? Does it:

2条回答
  •  广开言路
    2020-12-03 00:25

    Expired items aren't immediately removed from the cache, they're just marked as expired. You don't get a callback until a cache miss. I ran into this back in the ASP.NET 1.1 days, and it hasn't changed.

    There may be cases where expired items are removed immediately - such as if there's low memory and high CPU - but you can't count on it.

    I usually use a timer that reloads the cache on a regular basis.

提交回复
热议问题