What caching algorithm does ASP.Net use?

176 Views Asked by At

I'm writing a wrapper around ASP.Net's cache and I'm curious as to what caching algorithm they use. For instance, assuming everything in the cache has the same expiration date and priority, how does it clear out items?

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

1

There are 1 best solutions below

1
On

The algorithms you described are for determining when to remove items from a cache when it becomes full. The ASP.NET cache, however, does not have a set capacity - it lives on the heap so it's size is unbound.

Internally the cache has a timer that ticks at a regular frequency. At every tick it looks for expired items and removes them. If an item has a sliding expiration then every cache-get will increase its lifespan, otherwise it's removed.

UPDATE:

I've gone through the Cache class, and there is in fact logic that removes a certain percentage of 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's some pretty complex logic in the UsageBucket class which I can't comprehend right now, but if the names of the methods are anything to go by it doesn't seem to be any particular exotic caching algorithm, but something based on the least-frequently-used algo.

So I guess I was wrong :)