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.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce CacheEntry size #45962
Reduce CacheEntry size #45962
Changes from all commits
227c96d
5c8b862
4b529fb
c04da17
217ab43
c6597db
c519666
4a5715a
f170e8d
01a2686
0c07731
46ae2ea
c3e75ea
f582eb6
6a39239
58d6a0e
a1fcbd1
356e02f
9b189eb
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why doesn't this need a lock like the other two methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#45962 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where else is this locked on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#45962 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how that answers my question. My primary concern would be if it'd ever be possible for something to take the second lock and then try to take the first, creating a priority inversion and deadlock potential. I'm simply wondering if that's possible. Does the child/parent nature of this guarantee locks are always acquired in the same order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it does in the case when the cache item is being added to the cache (by calling the Dispose method):
runtime/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs
Lines 155 to 157 in 6e111ea
but I am not 100% sure if it would not be possible to create a code that does this and abuses the second possible call to this method from the
Cache.TryGetValue
method (which is very unintuitive for me):runtime/src/libraries/Microsoft.Extensions.Caching.Memory/src/MemoryCache.cs
Lines 237 to 239 in 6e111ea
FWIW I have not changed the locking order, it's the same as it used to be so far:
runtime/src/libraries/Microsoft.Extensions.Caching.Memory/src/CacheEntry.cs
Lines 331 to 340 in 6e111ea
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why in some cases are we using a for loop with direct indexing to enumerate the contents and in others we're using foreach?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know as I am not the author of the original code. To minimize the diff and make the review easier I've decided to change as few things as possible