Repository navigation
Cache home page and menu brands and collections per customer groups - #934
Merged
Merged
Conversation
The home page brand and collection blocks and the top menu's brand and collection lists were cached per store and language only, although the lists are filtered by the customer's groups. The first visitor's list was served to everyone: a group-limited collection showed up for guests and its link returned 404, and in the other order a group member lost it. Add the customer's group ids to the four keys, as the category home page and menu keys already do. The keys keep their Grand.brand. and Grand.collection. prefixes, so entity invalidation still clears them.
GetMenuHandler joined the customer's group ids three times per request; compute them once and reuse for the category, brand and collection keys. Cover the store and language parts of the home page and menu keys: a different store or language must not reuse another one's cached entry.
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.
Type: bugfix
Issue
The home page brand and collection blocks, and the brand and collection lists in the top menu, were cached per store and language only. The lists themselves are filtered by the customer's groups, so the first visitor's list was served to everyone:
To reproduce on
develop: limit a collection that is shown on the home page to the Registered group, restart, log in as a registered customer and open the home page, then open it as a guest in a private window. The guest sees the collection.Solution
Add the customer's group ids to
BRAND_HOMEPAGE_KEY,COLLECTION_HOMEPAGE_KEY,BRAND_NAVIGATION_MENUandCOLLECTION_NAVIGATION_MENU, the same way the category home page and menu keys already do. The keys keep theirGrand.brand./Grand.collection.prefixes, so the existing entity invalidation still clears them.Breaking changes
None for shipped code. The four
CacheKeyConstconstants now take a third format argument (the group ids); external code that formats them with two arguments must add it when recompiled.Testing
dotnet test src/Tests/Grand.Web.Tests— newGetHomepageBrandsHandlerTests,GetHomepageCollectionsHandlerTestsandGetMenuHandlerTestsrun both visit orders against a realMemoryCacheBase; they fail ondevelopand pass here.