Skip to content

Cache home page and menu brands and collections per customer groups - #934

Merged
KrzysztofPajak merged 2 commits into
developfrom
fix/homepage-cache-customer-groups
Oct 17, 2026
Merged

KrzysztofPajak merged 2 commits into
developfrom
fix/homepage-cache-customer-groups

Conversation

@KrzysztofPajak

Copy link
Copy Markdown
Member

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:

  • a collection or brand limited to a customer group appeared on the home page and in the menu for guests once a group member had visited, and its link returned 404;
  • in the other order, a group member did not see it.

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_MENU and COLLECTION_NAVIGATION_MENU, the same way the category home page and menu keys already do. The keys keep their Grand.brand. / Grand.collection. prefixes, so the existing entity invalidation still clears them.

Breaking changes

None for shipped code. The four CacheKeyConst constants now take a third format argument (the group ids); external code that formats them with two arguments must add it when recompiled.

Testing

  1. dotnet test src/Tests/Grand.Web.Tests — new GetHomepageBrandsHandlerTests, GetHomepageCollectionsHandlerTests and GetMenuHandlerTests run both visit orders against a real MemoryCacheBase; they fail on develop and pass here.
  2. In the admin, limit one home page collection and one brand (also set "Include in top menu") to the Registered group. Restart the app.
  3. Open the home page as a guest: neither item is shown.
  4. Log in as a registered customer: both items are shown on the home page and in the menu.
  5. Open the home page as a guest again: neither item is shown.

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.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 04:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.
@KrzysztofPajak
KrzysztofPajak merged commit b4a8c9e into develop Oct 17, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/homepage-cache-customer-groups branch October 17, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants