-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Cache null dictionary values by key #15576
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
Cache null dictionary values by key #15576
Conversation
|
Hi there @callumbwhyte, thank you for this contribution! 👍 While we wait for one of the Core Collaborators team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:
Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution. If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request. Thanks, from your friendly Umbraco GitHub bot 🤖 🙂 |
|
Hi @callumbwhyte! Thanks for your PR to fix #15533, where there is a performance hit if null values need to be looked up in the DB. One of the Core Collaborators team will review this as soon as possible - and from the issue it seems like one that we'll want HQ to have a glance over too, so we'll contact them about it! (cc @Migaroez) Best wishes Emma |
|
Code wise this look what we proposed 👍 |
src/Umbraco.Infrastructure/Cache/DefaultRepositoryCachePolicy.cs
Outdated
Show resolved
Hide resolved
|
Hi @callumbwhyte , Thanks for your PR! Cheers! |
|
Any updates/progress on this 😄 this would be super nice to have! |
|
Any chans this is going to make the 13.6 release 😅 @Migaroez |
|
I've made some updates to this to resolve the issues raised by @mikecp above. Think I have the logic right now. It wasn't quite as simple as first thought, as I realised if we cache a literally null value, we then can't tell from the cache retrieval if we have found a cached value or not... the value will be null in the case of an existing value that's not yet cached, or a cached null value. So I've got around this by caching a string to represent null, and then built the logic around that. It needs a further review of my amends, so if @mikecp, @Migaroez or @callumbwhyte would like to, please do, and hopefully we can get this into 13+. To test I've added the following to a view and created one dictionary item and not the other: I've confirmed I see the expected value on the front-end. And I've added a debugger to the Finally I've populated the |
|
@AndyButland Changes look good to me! Thanks for picking this up - I've been meaning to come back to this for some time, but time seems to be the exact issue for me lately...! |
src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.Repositories.cs
Outdated
Show resolved
Hide resolved
src/Umbraco.Infrastructure/Cache/DefaultRepositoryCachePolicy.cs
Outdated
Show resolved
Hide resolved
AndyButland
left a 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.
Review and testing steps described in #15576 (comment)
Requested amends have been handled.
|
This pull request has been mentioned on Umbraco community forum. There might be relevant details there: |
|
Hi, Just a heads up, this appears to effect subsequent lookups of dictionary items by their key (the string key, not the guid id). that have been just created, e.g if an item has just been created then looking for it by this key returns null. // code to create some dictionary (item) here...
_localizationService.Save(item);
// later in sequence....
// lookup
_localizationService.GetDictionaryItemByKey(keyString);I am not sure how this works on v13.6.0 but not v13.7.0 - and this does look like the only change around that. |
|
This pull request has been mentioned on Umbraco community forum. There might be relevant details there: https://forum.umbraco.com/t/dictionary-cache-regression/6041/4 |
As discussed on #15533 a small performance issue can exist at scale whereby each subsequent call to
Umbraco.GetDictionaryValue("...")for non-existent keys results in a database lookup.This PR implements an option to cache null values in the repository layer, and enables for the
DictionaryByKeyRepositoryrepository, following @Migaroez's stellar recommended implementation here.