Cache improvements: support reference identity and no eviction mode#18859
Merged
Conversation
Contributor
|
706b850 to
ecc77e7
Compare
6abe415 to
41fd06f
Compare
Contributor
Author
|
I removed from this PR any changes that plugged the cache in additional places where ConcurrentDictionary was in use before. This would be best to do in another PR for easy revert if there are problems. |
T-Gro
reviewed
Aug 28, 2025
T-Gro
approved these changes
Aug 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve
Cacheto make it usable in more places where we currently useConcurrentDictionary.The interface is now compatible with
ConcurrentDictionaryso it can be easily swapped now to get telemetry and, if needed, eviction.Changes include:
Added back
NoEvictionmode, that makes the cache into a thinConcurrentDictionarywrapper.Added option for custom identity for keys,
HashIdentity.Referenceis now supported.Added store rebuilding during eviction: if key identity is not 100% reliable, (e.g. type subsumption cache keys) we can end up with unreachable entries that cannot be evicted. If those build up enough, we just drop the old store and build a new one with good keys only.
Added graceful disposal for caches of shorter lifetime. Finalizer will now cancel and dispose the background eviction mailbox processor. Telemetry now includes counts of creations and disposals.
Factored away the telemetry, so nothing is allocated by the cache itself.
Added sensible methods, GetOrAdd, AddOrUpdate. The current interface is:
Some more tests are added, too.