我编写了一个 cron 作业,它检查直接在数据库中进行的库存数量更改,因此绕过了 Magento 核心,该核心可以处理缓存过期。
我希望能够通过以下方式使用对象管理器:
public function clearCacheforProduct($productID) {
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$cacheManager = $objectManager->get('\Magento\Framework\App\Cache\Manager');
$cacheManager->clean('catalog_product_' . $productID);
}
Run Code Online (Sandbox Code Playgroud)
当前,当 cron 作业运行时,这会以静默方式失败。
知道如何清除单个产品 ID 的缓存吗?