Skip to Content

AD0-E718: Which steps to make sure vcl_hash function of Varnish also considers the newly created attribute?

Question

An Architect working on a headless Adobe Commerce project creates a new customer attribute named my_attribute. Based on the attribute value of the customer, the results of GraphQl queries are modified using a plugin. The frontend application is communicating with Adobe Commerce through Varnish by Fastly, which is already caching the queries that will be modified. The Adobe Commerce Fastly extension is installed, and no other modifications are made to the application.

Which steps should the Architect take to make sure the vcl_hash function of Varnish also considers the newly created attribute?

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.

Answer

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.

Explanation

The correct answer is 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.

The vcl_hash function of Varnish uses the cache ID to determine whether a request should be served from cache or from the application. The cache ID is generated by the Magento GraphQlCache module, and it includes the values of all of the customer attributes that are used in the GraphQl queries.

To make sure that the vcl_hash function also considers the newly created attribute, you need to create a new class that inherits from Magento\GraphQlCache\Model\CacheId\CacheIdFactorProviderInterface. This class will be responsible for returning the value of the newly created attribute from the getFactorValue function. You will also need to return the name of the attribute from the getFactorName function.

Once you have created this class, you need to add it through DI to the IdFactorProviders array of Magento\GraphQlCache\Model\CacheID\CacheIdCalculator. This will ensure that the value of the newly created attribute is included in the cache ID.

Here is a more detailed explanation of the steps involved:

  1. Create a new class that inherits from Magento\GraphQlCache\Model\CacheId\CacheIdFactorProviderInterface.
  2. In the getFactorValue function, return the value of the newly created attribute.
  3. In the getFactorName function, return the name of the newly created attribute.
  4. Add the class through DI to the IdFactorProviders array of Magento\GraphQlCache\Model\CacheID\CacheIdCalculator.

Once you have completed these steps, the vcl_hash function of Varnish will also consider the newly created attribute when generating the cache ID. This will ensure that the results of GraphQl queries that are modified by the plugin are cached by Varnish.

Here are some of the benefits of caching GraphQl queries:

  • Improved performance: Caching GraphQl queries can improve the performance of your application by reducing the number of requests that are made to the Magento Commerce backend.
  • Reduced load on the backend: Caching GraphQl queries can reduce the load on the Magento Commerce backend by serving cached queries from Varnish instead of from the Magento Commerce application.
  • Increased scalability: Caching GraphQl queries can help to improve the scalability of your application by allowing you to handle more requests without increasing the load on the Magento Commerce backend.

Reference

Adobe Commerce Architect Master AD0-E718 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Adobe Commerce Architect Master AD0-E718 exam and earn Adobe Commerce Architect Master AD0-E718 certification.