Question

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 ***************

Was it helpful?

Solution 2

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top