Skip to content

Conversation

@MarkCiliaVincenti
Copy link

@MarkCiliaVincenti MarkCiliaVincenti commented Dec 27, 2025

Motivation and Context

The current MemoryCacheExtensions allocates a SemaphoreSlim object every time GetOrCreateAtomicAsync is called on an object that is not currently in the memory cache. We can reduce memory allocations through pooling.

Description

The solution uses the battle-tested AsyncKeyedLock library (note: I am the author of this library), which is already used in Microsoft projects such as Kiota and Vipr and has also been used in situations to prevent cache stampede (e.g. FusionCache) and in important projects such as ABP Framework.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible

@github-actions github-actions bot changed the title MemoryCacheExtensions semaphore pooling .NET: MemoryCacheExtensions semaphore pooling Dec 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants