I wrote an extension in which a base abstract class contains a function that will extract a product collection:
$cache = Mage::app()->getCache();
if(!$cache->load('itserv_feed_collection')) {
$_productCollection = Mage::getModel('catalog/product')->getCollection();
$_productCollection->addAttributeToSelect('*');
$_productCollection->addAttributeToSelect('stock_status');
$_productCollection->addAttributeToSelect(Mage::getStoreConfig('feed_options/mappa_attributi/produttore'));
$_productCollection->addAttributeToSelect(Mage::getStoreConfig('feed_options/mappa_attributi/ean'));
$_productCollection->addAttributeToSelect(Mage::getStoreConfig('feed_options/mappa_attributi/mpn'));
$_productCollection->addAttributeToFilter('type_id', Mage_Catalog_Model_Product_Type::TYPE_SIMPLE);
$cache->save(serialize($_productCollection), "itserv_feed_collection", array("itserv_feed_collection"), 120);
}
else {
$_productCollection = unserialize($cache->load('itserv_feed_collection'));
}
return $_productCollection;
Each of the child classes extending from this class will use the same collection in the same runtime stack. I want to save this collection within the cache (as you can see looking at the code), so since the second time a child class will use it, the script will not need to load it again.
The problem is that it is impossible to use cache, because cache needs a serialized Collection and, in this case, i cannot do it because the collection contains the Mage_Core_Model_Config_Element that can't be serialized (it triggers the famous error "Serialization of 'Mage_Core_Model_Config_Element' is not allowed").
I tried different solutions, even json_encode/json_decode instead of serialize/unserialize, but i can't solve the problem.
Do you have some solution? Thanks!