Hi, Your problem is that you're attempting to serialize (indirectly) a SimpleXML object - one of PHP's internal classes. To successfully serialize, a common tactic is to utilise custom serialize functions as described here: http://blog.makemepulse.com/2007/09/27/serialize-and-unserialize-simplexml-in-php/
The tactic basically converts all SimpleXMLElements to stdClass (the base XML is stored as a stdClass property). Unserialising from the cache would reconstruct the SimpleXMLElement objects on the fly. Unfortunately this means you're caching the XML, not a pre-parsed form, so it has a performance penalty to a degree. To implement this, you would need to override the save() and load() methods of Zend_Cache_Core to replace the serialize/unserialize() calls with the custom version, and likewise override. This requires some inventive thinking in loading what will amount to a custom frontend (see the Zend_Cache factory() and other static methods to start with). Haven't done this for a while but perhaps someone on the list recalls the method of adding custom frontends? Paddy Pádraic Brady http://blog.astrumfutura.com http://www.patternsforphp.com OpenID Europe Foundation Member-Subscriber ________________________________ From: Ross Masters <ross.masters...@googlemail.com> To: fw-general@lists.zend.com Sent: Sunday, January 4, 2009 7:14:30 PM Subject: [fw-general] Zend_Cache problem Hi all, I'm relatively new with ZF and completely new to the lists - so I apologies if this is the wrong list. I'm trying to cache the Twitter public timeline for 60 seconds, using the code below: $frontendOptions = array( 'lifetime' => 60, 'automatic_serialization' => true ); $backendOptions = array('cache_dir' => APPLICATION_PATH . '/../tmp/'); $cache = Zend_Cache::factory( 'Core', 'File', $frontendOptions, $backendOptions); if (!($timeline = $cache->load('publicTimeline'))) { $timeline = $this->_twitter->status->publicTimeline(); $cache->save($timeline); } print_r($timeline); This works fine on the first run, but the second and later runs (up till the cache expires) I get this error: Warning: unserialize() [function.unserialize]: Node no longer exists in D:\twitter\library\Zend\Cache\Core.php on line 278 (x91) Zend_Rest_Client_Result Object ( [_sxml:protected] => SimpleXMLElement Object Warning: print_r() [function.print-r]: Node no longer exists in D:\twitter\application\modules\home\controllers\TimelineController.php on line 58 ( ) ) I've tried storing a simple array and a small stdClass Object and they work fine. I had an idea it could be to do with references but when I store an instance of Zend_Registry in the object that works fine too. I'm completely at a loss here - I'm practically following the reference guide examples. If anyone can help I'd be grateful. Regards, Ross (Extra) If I store $timeline->status rather than the whole $timeline object the array is stored but I still get 4 unserialize errors and this error: Warning: Home_TimelineController::publicAction() [home-timelinecontroller.publicaction]: Node no longer exists in D:\development\twitter\application\modules\home\controllers\TimelineController.php on line 53 ( Line 53: if (!($timeline = $cache->load('publicTimeline'))) { ) -- Ross Masters [EN, GMT+0] Twitter: @rossmasters