What caching algorithm does ASP.Net use?

I am writing a wrapper around the ASP.Net cache, and I'm curious what kind of caching algorithm they use. For example, if everything in the cache has the same date and priority, how do I clear the items?

Wikipedia contains 11 different caching algorithms. Does ASP.Net use one of them?

+4
source share
1 answer

The algorithms you described are designed to determine when to remove items from the cache when it is full. The ASP.NET cache, however, does not have an installed capacity - it lives on the heap, so the size is not related.

Inside the cache there is a timer that ticks at a regular frequency. At each tick, it searches for expired items and removes them. If the element has a sliding ending, then each cache-get increases its service life, otherwise it is deleted.

UPDATE:

I went through the Cache class, and there really is a logic that removes a certain percentage of the least used items when the "memory pressure" gets too high. You can see this in Reflector if you go to System.Web.UI.Caching.CacheMemoryStats.GetPercentToTrim() and CacheCommon.CacheManagerThread(Int32) . There is a rather complicated logic in the UsageBucket class that I cannot understand right now, but if the method names cannot do anything, it does not seem to be some kind of special exotic caching algorithm, but something based on the least frequently used algo.

So, I think I was wrong :)

+3
source

All Articles