GordonLesti / Lesti_Fpc

Simple Magento Fullpagecache
https://gordonlesti.com/lesti-fpc-documentationversion-1-4-5/
Other
358 stars 158 forks source link

how check if product have cache already by product id #224

Closed OlgaBurtyka closed 8 years ago

OlgaBurtyka commented 8 years ago

Hi! Thank you for your extension. Can you, please, say me one thing. I used magento 1.4. For clean cache by product ID i used this code :

$fpcModel = Mage::getSingleton('fpc/fpc'); if (is_object($fpcModel)) {

foreach ($arrayAllProductIds as $productIdForCleanCache) {
    $fpcModel->clean(sha1('product_' . $productIdForCleanCache));
}

} How I can check if product have cache by product id already? Thanks.

GordonLesti commented 8 years ago

Hello @OlgaBurtyka Lesti_Fpc_Model_Fpc is just extending from Mage_Core_Model_Cache, but this class has the function getFrontend. This function will return an object of type Zend_Cache_Core and there exists the function getIdsMatchingAnyTags or maybe better getTags. Maybe a possible solution for you can be:

$fpcModel = Mage::getSingleton('fpc/fpc');
$arrayAllProductIds = array_map(
        function($value) {
            return sha1('product_' . $value);
        },
        $arrayAllProductIds
    );
$arrayAllProductIds = array_intersect(
        $arrayAllProductIds,
        $fpcModel->getFrontend()->getTags()
    );
$fpcModel->clean($arrayAllProductIds);

I hope this will help you, but please note this works also:

$fpcModel = Mage::getSingleton('fpc/fpc');
$arrayAllProductIds = array_map(
        function($value) {
            return sha1('product_' . $value);
        },
        $arrayAllProductIds
    );
$fpcModel->clean($arrayAllProductIds);
OlgaBurtyka commented 8 years ago

Thank you very much for your answer.