gsharp
gsharp

Reputation: 27927

MemoryCache AbsoluteExpiration

When using MemoryCache it's possible to set

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" ?

Upvotes: 8

Views: 10433

Answers (1)

Evk
Evk

Reputation: 101453

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.

Upvotes: 12

Related Questions