1

We are using Magento Enterprise and use flat tables and automatic re-index.

I have a block that extends Mage_Catalog_Block_Product_List. Block cache is enabled and block cache is tagged with all the products it contains. When I save any of the products that are in the block in the admin, the block cache is deleted. This all works correctly.

The problem appears when I enable flat tables. When the product is changed in backend the block cache is deleted, but product flat tables are not yet updated. The new block cache is created with old data. I must be missing something, because this would not work for anyone using flat tables. And this is all Magento "core".

How should I approach solving this? I there an event being fired, that I should be observing?

Any suggestion would be greatly appreciated.

**************** EDIT ***************

Let me try to clarify:

  1. Product has name "My cool product"
  2. EAV, flat tables and block HTML cache contain "My cool product"
  3. Change name to "My cool product with new name"
  4. Block HTML cache gets deleted
  5. EAV contains "My cool product with new name" but flat table still contains "My cool product" (reindex has not happened)
  6. Customer visits the website and a new block HTML cache is generated from flat tables data which still contains "My cool product"
  7. EAV contains "My cool product with new name", flat tables and block HTML cache still contain "My cool product"
  8. Reindex runs
  9. EAV and flat tables contain "My cool product with new name" but block HTML cache still contains "My cool product"

Time between points 1 and 7 is less than a second.

**************** EDIT ***************

1
  • try to reindex catalog_product_flat Commented Nov 2, 2016 at 15:52

2 Answers 2

0

After making any changes in product level, then you are required to do a re-index and then flush cache.

2
  • 1
    there is no point to fully flush the cache if you change only one product, as the OP states.
    – Marius
    Commented Nov 3, 2016 at 8:16
  • Please read my question. Re-index happens. The problem is, that re-index happens later than new HTML cache generation.
    – TheBlaze
    Commented Nov 3, 2016 at 8:29
0

I ended up implementing an observer for "catalog_product_flat_partial_reindex". The observer gets list of product IDs that the indexer just finisher re-indexing. I load a collection from these IDs and call cleanModelCache() on all products.

    $productIds = $observer->getEvent()->getProductIds();
    if(is_array($productIds)){
        $productCollection = Mage::getModel("catalog/product")->getCollection()
            ->addFieldToFilter("entity_id", array("in"=>$productIds));

        foreach ($productCollection as $product){
            $product->cleanModelCache();
        }
    }

This means that all blocks that are tagged with product in the collection, will be cleared from cache after the data in the flat tables have been refreshed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.