Describe the bug
If I make a call to MemoryCache.Set() to update an existing item when the cache is full (size limit reached), the item is instead removed.
To Reproduce
Steps to reproduce the behavior:
LINQPad script: http://share.linqpad.net/kmpxj3.linq
void Main()
{
var memoryCache = new MemoryCache(new MemoryCacheOptions
{
SizeLimit = 1 // <-- Setting to 2 fixes the issue
});
Set(memoryCache);
memoryCache.Get("A").Dump(); // Yields 1
Set(memoryCache);
memoryCache.Get("A").Dump(); // Yields null
}
private void Set(MemoryCache memoryCache)
{
//memoryCache.Remove("A"); // <-- Also fixes the issue
memoryCache.Set("A", 1, new MemoryCacheEntryOptions
{
AbsoluteExpirationRelativeToNow = TimeSpan.FromDays(1),
SlidingExpiration = TimeSpan.FromDays(1),
Size = 1
});
}
Expected behavior
I would expect the item to be updated.
Additional Info
Initially posted a question here:
https://stackoverflow.com/questions/60626316/2nd-call-to-memorycache-set-with-the-same-key-erases-entry-if-cache-is-full
There was a link added by another user to a related, closed bug: dotnet/extensions#1889
While this is a different scenario, it seems like it might have the same root cause.
Describe the bug
If I make a call to
MemoryCache.Set()to update an existing item when the cache is full (size limit reached), the item is instead removed.To Reproduce
Steps to reproduce the behavior:
LINQPad script: http://share.linqpad.net/kmpxj3.linq
Expected behavior
I would expect the item to be updated.
Additional Info
Initially posted a question here:
https://stackoverflow.com/questions/60626316/2nd-call-to-memorycache-set-with-the-same-key-erases-entry-if-cache-is-full
There was a link added by another user to a related, closed bug: dotnet/extensions#1889
While this is a different scenario, it seems like it might have the same root cause.