Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MemoryCache AbsoluteExpiration

When using MemoryCache it's possible to set

  • AbsoluteExpiration
  • AbsoluteExpirationRelativeToNow

Example:

    cache.GetOrCreate("key", f =>
    {
         f.AbsoluteExpiration = new DateTimeOffset(DateTime.Today.AddDays(1));
         f.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
        return "item";
    });

Can both property be set at the same time, and the one that expires first will apply? Or will the last property that has been set be the "master" ?

like image 552
gsharp Avatar asked Mar 09 '18 09:03

gsharp


1 Answers

Since those properties are of interface (ICacheEntry) - how they behave depend on concrete implementation. If we take default MemoryCache (and corresponding CacheEntry implementation) - then yes, they both can be set and, since they both represent absolute expiration, whichever happens earlier will be in effect and the other will be ignored.

like image 99
Evk Avatar answered Sep 19 '22 11:09

Evk