-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Remove unnecessary deserialization actions #14904
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -364,23 +364,20 @@ protected async Task InvalidateInternalAsync(TDocument document, bool failover = | |||||||
|
||||||||
private async Task<TDocument> GetFromDistributedCacheAsync() | ||||||||
{ | ||||||||
byte[] data = null; | ||||||||
|
||||||||
if (_isDistributed) | ||||||||
{ | ||||||||
data = await _distributedCache.GetAsync(_options.CacheKey); | ||||||||
byte[] data = await _distributedCache.GetAsync(_options.CacheKey); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
if (data == null) | ||||||||
{ | ||||||||
return null; | ||||||||
} | ||||||||
return await _options.Serializer.DeserializeAsync<TDocument>(data); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an empty line after the ending There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
else if (_memoryCache.TryGetValue<TDocument>(_options.CacheKey, out var cached)) | ||||||||
{ | ||||||||
data = await _options.Serializer.SerializeAsync(cached); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In fact there is a reason for doing this, this only happens if not distributed and on updating, when we want to get a mutable document for updating for which we don't want to return a shared document from the memory cache. So serializing and deserializing is a way to clone the document. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for your reply. I didn't think of these, maybe we should add some notes to the text here |
||||||||
} | ||||||||
|
||||||||
if (data == null) | ||||||||
{ | ||||||||
return null; | ||||||||
return cached; | ||||||||
} | ||||||||
|
||||||||
return await _options.Serializer.DeserializeAsync<TDocument>(data); | ||||||||
return null; | ||||||||
} | ||||||||
|
||||||||
private async Task UpdateDistributedCacheAsync(TDocument document) | ||||||||
|
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.
Use
var data
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.
You can use the suggestion feature instead