组件和 GraphQL 清除缓存 clear-cache
本文档提供了有关在AEM CIF中启用和验证clear-cache功能的综合指南。
在CIF配置中启用清除缓存功能 enable-clear-cache
默认情况下,CIF配置中禁用清除缓存功能。 要启用该功能,您需要将以下内容添加到相应的项目中:
-
启用Servlet
/bin/cif/invalidate-cache,这有助于通过在您的项目中添加项目中的com.adobe.cq.cif.cacheinvalidation.internal.InvalidateCacheNotificationImpl.cfg.json配置来触发清除缓存API及其相应请求,如此处所示。note note NOTE 只需为创作实例启用配置。 -
通过在您的项目中添加
com.adobe.cq.commerce.core.cacheinvalidation.internal.InvalidateCacheSupport.cfg.json配置,使侦听器能够从AEM的每个实例(发布和创作)中清除缓存,如此处所示。-
应为创作实例和发布实例启用配置。
-
启用Dispatcher缓存(可选):您可以通过在上述配置中将
enableDispatcherCacheInvalidation属性设置为true来启用Dispatcher清除缓存设置。 这提供了从Dispatcher清除缓存的功能。note note NOTE 这仅适用于发布实例。 -
此外,请确保提供适合您的产品、类别和CMS页面的相应模式,并将其添加到上述配置文件中,以便将其从Dispatcher缓存中删除。
-
-
要提高SQL查询查找与产品和类别相关的相应页面的性能,请在项目中添加相应的索引(推荐)。 有关详细信息,请参阅cifCacheInvalidationSupport。
验证清除缓存功能 verify-clear-cache
要验证是否正确设置了所有内容,请执行以下操作:
- 将相应的servlet触发到创作实例AEM,例如http://localhost:4502/bin/cif/invalidate-cache,您应会收到200 HTTP响应。
- 验证已在创作实例中的以下路径下创建节点:
/var/cif/cacheinvalidation。 节点名称遵循以下模式:cmd_{{timestamp}}。 - 验证是否已在每个发布实例中创建相同的节点。
现在,要检查缓存是否正确清除,请执行以下操作:
-
导航到相应的PLP和PDP页面。
-
在商业引擎中更新产品或类别名称。 根据缓存配置,这些更改不会立即反映在AEM中。
-
触发servlet API,如下所示:
code language-none curl --location '{Author AEM Instance Url}/bin/cif/invalidate-cache' \ --header 'Content-Type: application/json' \ --header 'Authorization: ******' \ // Mandatory --header 'Cookie: private_content_version=0299c5e4368a1577a6f454a61370317b' \ --data '{ "productSkus": ["Sku1", "Sku2"], // Optional: Pass the corresponding sku which got updated. "categoryUids":["CategoryUid"], // Optional : Pass the corresponding category-uid which got updated. "storePath": "/content/venia/us/en", // Mandatory : Needs to be given to know for which site we are removing the clear cache. }'
如果一切顺利,新变化将反映在所有实例中。 如果更改在发布实例上不可见,请尝试在私人/无痕浏览器窗口中访问相关的PLP和PDP页面。
清除缓存失效API clear-cache-api
当您想要从AEM中清除商业相关数据的缓存时,需要触发此API。
请求类型: POST
标头 headers
Content-Typeapplication/jsonAuthorization负载 payload
下表显示了特征现成的现有属性。 这些InvalidateType属性需要与必需属性(如storePath)一起提供。
invalidateTypeproductSkus使用以下模式从内部内存中清除缓存:"\"sku\":\\s*\""
Dispatcher
- 清除相应SKU的PDP页面缓存
- 清除其所在的相应类别页面的缓存(基于来自商业的graphql响应)
- 基于以下查询清除缓存:
SELECT content.[jcr:path] FROM [nt:unstructured] AS content<br>WHERE ISDESCENDANTNODE(content, '{storePath}')<br>AND ( (content.[product] IN ('sku1','sku2') AND content.[productType] = 'combinedSku')<br> OR (content.[selection] IN ('sku1','sku2') AND content.[selectionType] IN ('combinedSku', 'sku')))
categoryUids使用以下模式从内部内存中清除缓存:"\"uid\"\\s*:\\s*\\{\"id\"\\s*:\\s*\""
Dispatcher
- 清除相应数据的类别页面缓存(包括其子类别页面)
- 清除具有相应类别的所有PDP页面
- 基于以下查询清除缓存:
SELECT content.[jcr:path] FROM [nt:unstructured] AS content<br>WHERE ISDESCENDANTNODE(content,'{storePath}')<br>AND ((content.[categoryId] in ('category1','category2')<br>AND content.[categoryIdType] in ('uid'))<br>OR (content.[category] in ('category1','category2') AND content.[categoryType] in ('uid')))
regexPatternscacheNamesinvalidateAll下表显示在每个API调用中需要传递的必需属性:
storePath/content/venia/us/en作为对Venia项目的引用)。invalidateType.的组合提供此值示例API请求 sample-request
curl --location 'https://author-p10603-e145552-cmstg.adobeaemcloud.com/bin/cif/invalidate-cache' \
--header 'Content-Type: application/json' \
--header 'Authorization: ******' \
--header 'Cookie: private_content_version=0299c5e4368a1577a6f454a61370317b' \
--data '{
"productSkus": ["VP01", "VT10"], // This will clear cache for the corresponding pages related with mentioned skus.
"categoryUids":["Mjk="], // This will clear cache for the corresponding pages related with mentioned categories.
"regexPatterns":["\"uid\"\\s*:\\s*\\{\"id\"\\s*:\\s*\"(Mjk=)\"", "\"sku\":\\s*\"(VP02|VP03)\""],
"cacheNames": ["venia/components/commerce/product"], // If this been added then it will clear respective caches for the corresponding storepath
"storePath": "/content/venia/us/en"
}'
可扩展性 clear-cache-extensibility
此功能不仅提供了其核心功能,而且还提供了可扩展性,允许开发人员根据需要进一步对其进行构建和自定义。
扩展现有属性 existing-attribute
如果需要清除现有基于属性的功能(如categoryUids)当前未涵盖的缓存,您可以引用此参考文件以添加新模式并定义应从缓存中清除的超出当前实现处理范围的其他invalidatePaths。
添加新的自定义属性 new-custom-attribute
例如,如果不想使用现有属性来清除缓存,则可以灵活地创建自己的属性并定义其相应的功能。