Skip to content

Don't trim if MemoryCache is already empty.#51762

Merged
StephenMolloy merged 1 commit intodotnet:mainfrom
StephenMolloy:SRC-DivideByZero
May 6, 2021
Merged

Don't trim if MemoryCache is already empty.#51762
StephenMolloy merged 1 commit intodotnet:mainfrom
StephenMolloy:SRC-DivideByZero

Conversation

@StephenMolloy
Copy link
Copy Markdown
Member

Don't trim an empty MemoryCache

There exists the potential for an empty MemoryCache to
be trimmed under memory pressure. When this happens,
the result is a DivideByZero exception. The solution is to
not trim empty caches, since doing so doesn't make
any sense anyway.

Fix #1423

@StephenMolloy StephenMolloy merged commit dd87a86 into dotnet:main May 6, 2021
@karelz karelz added this to the 6.0.0 milestone May 20, 2021
sw.Stop();
// 1) don't update stats if the trim happend because MAX_COUNT was exceeded
// 2) don't update stats unless we removed at least one entry
if (percent > 0 && trimmedOrExpired > 0)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(late to the game, but ...) any reason why you check percent again?

@ghost ghost locked as resolved and limited conversation to collaborators Jun 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Runtime.Caching.MemoryCacheStatistics.SetTrimStats DivideByZeroException

4 participants