QuestionQ19

Troubleshoot infrastructure and configuration issues

An existing Adobe Commerce website is being moved to a headless implementation.

The existing site includes an All Brands page and separate pages for every brand. All brand-related pages are cached in Varnish with tags, in the same way as products and categories.

Two new GraphQL queries have been created to expose this information to the frontend for the new headless implementation:

Question Image

During testing, the queries occasionally return stale information. How should this issue be resolved while preserving performance?

  • A Specify a $cache(cacheable: false) directive for each GraphQL query, making sure that the data returned is not cached, and is up to date
  • B Specify a @cache(cacheIdentity: Path\To\IdentityClass) directive for each GraphQL query, corresponding to a class that adds cache tags for relevant brands and associated products
  • C Each GraphQL query’s resolver class should inject \Magento\GraphQlCache\Model\CacheableQuery and call setCacheValidity(true) on it as part of the resolver’s resolve function
Explanation

A cacheable custom GraphQL query should use the @cache(cacheIdentity: "...") directive and an identity class that generates the relevant cache tags. Those tags let changes to a brand or its associated products invalidate the affected Varnish-cached responses, so subsequent requests return current data without disabling caching. Adobe Commerce documents that cacheIdentity points to the class that retrieves cache tags, while @cache(cacheable: false) is intended to disable caching rather than provide cache invalidation.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!