QuestionQ2

Content, CMS, and Storefront

An Architect on a headless Adobe Commerce project creates a new customer attribute named my_attribute. Based on the customer’s attribute value, a plugin modifies the results of GraphQL queries. The frontend application communicates with Adobe Commerce through Varnish by Fastly, which already caches the queries that will be modified. The Adobe Commerce Fastly extension is installed, and no other changes are made to the application.

Which steps should the Architect take to ensure that Varnish’s vcl_hash function also takes the newly created attribute into account?

  • A Create a new class inheriting from Magento\Framework\GraphQl\Query\Resolver\IdentityInterface and returning the value of my_attribute from the getIdentities function. Then specify a @cache(cacheIdentity: Path\To\IdentityClass) directive for each GraphQL query to include the newly created IdentityClass to each query that adds the cache tags for each customer.
  • B Create a new class inheriting from Magento\GraphQlCache\Model\CacheId\CacheIdFactorProviderInterface and returning the value of my_attribute from the getFactorValue function and my_attribute from getFactorName function. Then add this class through DI to the IdFactorProviders array of Magento\GraphQlCache\Model\CacheID\CacheIdCalculator.
  • C Create a new class inheriting from Magento\Customer\CustomerData\SectionSourceInterface and returning the value of my_attribute from the getSectionData function. Then add this class through DI to the sectionSourceMap array of Magento\Customer\CustomerData\SectionPoolInterface.
Explanation

Adobe Commerce calculates X-Magento-Cache-Id from registered cache-ID factors, and Fastly/Varnish uses that value to distinguish cached GraphQL responses for logged-in customers. Implementing CacheIdFactorProviderInterface to supply my_attribute as the factor name and its current customer value as the factor value, then registering it in CacheIdCalculator’s idFactorProviders DI argument, makes the cache identifier vary by that attribute. Cache identities control cache invalidation tags, while customer-data sections supply client-side private content and do not vary the Varnish GraphQL cache key.

Learn more

Community Discussion

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