My question is similair to this one, but the answers only explain why things happen the way they do, not how to actually achieve the desired solution.
Right now, when defining
var options = new MemoryCacheEntryOptions()
{
// After x minutes of non-access, remove
SlidingExpiration = TimeSpan.FromSeconds(x),
}
.RegisterPostEvictionCallback(OnCacheItemRemoved);
A cacheItem will only be removed when accessing it on a timepoint t1
> t0 + x'
. That means that if I do not access the item anymore after that point, it also will never be removed from cache.
I could set an absolute expiration yes, but that would overrule the sliding window. If I wanted it to stay in memory if it still being accessed, then it would be evicted due to the aboslute expiration. What I want is a simple sliding window with automatic eviction once the item hasn’t been accessed in x
minutes. I’d expect an internal timer to handle this. It does not need to run every second for performance reasons, once a minute is fine enough for me.
I do not see any configuration for how to check for eviction either.