If your Adobe Commerce (Magento) version is before 2.4.6, consider this blog intended for you, as Adobe Commerce (Magento) versions 2.4.6 and beyond already integrate the ACSD-53239 Adobe Commerce patch.
This patch is used to fix the issue where the Inventory (MSI) indexer cleans all caches instead of clearing the cache only for reindexing records while the indexer is in the Update By Schedule mode.
This patch is,
- Available in the Quality Patches Tool (QPT) version 1.1.36.
- Released on Aug 11, 2023.
- Created for Adobe Commerce (Magento) version 2.4.5.
- Compatible with Adobe Commerce (Magento) 2.4.3 to 2.4.5-p4.
Issue
Generally, while we add/update products on Adobe Commerce (Magento), the indexer will be reindexed in the background (While the indexer is in the Update By Schedule mode) and the MSI module uses the following plugin class to clear the cache,
vendor/magento/module-inventory-cache/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/CacheFlush.php. Which uses the following two classes for cleaning categories and products cache by tags,
- vendor/magento/module-inventory-cache/Model/FlushCacheByProductIds.php
- vendor/magento/module-inventory-cache/Model/FlushCacheByCategoryIds.php
The vendor/magento/module-inventory-cache/Model/FlushCacheByCacheTag.php class will be used by both of the above classes to dispatch the event for cleaning the cache. In this file, we observe the code below in line number 60, which registers the cache context and dispatches the event.
$cacheContext->registerEntities($cacheTag, $entityIds);
$this->eventManager->dispatch('clean_cache_by_tags', ['object' => $cacheContext]);
$this->appCache->clean($cacheContext->getIdentities());
The method registerEntities is being used, but the class vendor/magento/module-indexer/Model/Indexer/DeferCacheCleaning.php contains an around plugin that does not add any IDs to cache context. This issue causes the cleaning of almost all tags that are saved instead of clearing the cache only for reindexing records.
Solution
Adobe Commerce (Magento) has issued the patch ACSD-53239, which resolves this issue. Applying this patch will update the following code in the file vendor/magento/module-inventory-cache/Model/FlushCacheByCacheTag.php in line no 62,
From,
$this->appCache->clean($cacheContext->getIdentities());
To,
$tags = $cacheContext->getIdentities();
if ($tags) {
$this->appCache->clean($tags);
}
The above code will only clear the cache for the identities returned from the cache context.
How to apply the patch in Magento 2?
Follow the steps below to install the patches in Magento 2,
- Install the latest quality patches package by using the command: composer requires magento/quality-patches
- After installing the quality patches tool, apply the patch by using the command: ./vendor/bin/magento-patches apply ACSD-53239
- Then clean the cache by using the command: ./bin/magento cache:clean
Conclusion
Adobe Commerce (Magento) will release various types of patches regularly that can help fix known issues and improve the website’s performance and security features. So website owners should apply those patches on their website with the help of Adobe Adobe-certified developer.