Can I find the last time a MemoryCache item was accessed?

644 Views Asked by At

In a .NET 4 MemoryCache, is there a way to find when an item was last accessed? I'm sure it's being tracked internally, since CacheItemPolicy has the SlidingExpiration property. But I haven't been able to find anywhere to read it.

Big picture, I'm looking for a way to manually remove the oldest n entries from a cache.

1

There are 1 best solutions below

0
On

It doesn't seems to be possible to obtain this information from the MemoryCache. You will have to use a wrapper on your items with a member for last-access-time and update it whenever an item is accessed.