Search code examples
c#memorycache

Memory Cache absoluteExpiration - Will this affect all entries in memory cache?


I am using MemoryCache.Default to cache the data for some time...

I did it using the Set method

DateTimeOffset cacheTimeOut = new DateTimeOffset(DateTime.Now.AddSeconds(2));
patientOrderCache.Set("abc", abcData, cacheTimeOut);

If the absoluteExpiration value is over, will it remove ALL cache entries in MemoryCache.Default?

Or, will it just remove the specified one (abc) ?

I am pretty sure it will just remove ONLY the specified entry (abc key and related data)...but just want to confirm as I didn't see any description related to that.. and my existing memory cache has so much of data that I am not aware of.


Solution

  • Or, will it just remove the specified one (abc) ?

    It will remove just the specified key abc for which you specified this expiration policy when you stored it into the cache.

    The other cache entries will be subject to the expiration policy you specified when you stored them (or the default policy if you didn't specify one explicitly).