AspNetCore.CacheOutput icon indicating copy to clipboard operation
AspNetCore.CacheOutput copied to clipboard

Cache does not expire as given

Open dimuthun opened this issue 7 years ago • 3 comments

Even in the demo app, Servicer Side Cache does not expire even I set the duration to a smaller span like 10 seconds. Debug into the code showed that in CheckForExpiredTime method in Microsoft.Extensions.Caching.Memory returns false due to _absoluteExpiration or _slidingExpiration being null.

    private bool CheckForExpiredTime(DateTimeOffset now)
    {
        if (_absoluteExpiration.HasValue && _absoluteExpiration.Value <= now)
        {
            SetExpired(EvictionReason.Expired);
            return true;
        }

        if (_slidingExpiration.HasValue
            && (now - LastAccessed) >= _slidingExpiration)
        {
            SetExpired(EvictionReason.Expired);
            return true;
        }

        return false;
    }

dimuthun avatar Jan 21 '19 07:01 dimuthun

Hey @dimuthun, I wrote InMemoryCacheOutputProvider in a hurry and just for demo purpose, because on most of my projects I'm using persisted providers. You can try to implement IApiCacheOutput by your own for now. I will try to fix the issue ASAP. Thank you.

Iamcerba avatar Jan 21 '19 08:01 Iamcerba

@dimuthun, try to download updated version 1.0.5.1 of the AspNetCore.CacheOutput.InMemory package and let me know if anything wrong.

Iamcerba avatar Jan 21 '19 09:01 Iamcerba

I checked and it works as expected. Thanks!

dimuthun avatar Jan 24 '19 16:01 dimuthun