Browsing articles tagged with " Zend_Cache"
Apr
22

Zend Cache and Zend Feed Problem

Today I ran into a problem while caching feeds using Zend_Cache. I decided that I wanted to cache the returned object by the Zend_Feed. I had something like this:

$rssFeedLink = 'http://www.smooka.com/blog/';
$cacheId = 'rss_feed';

$frontendOptions = array(
		   	'lifetime' => 1800, // cache lifetime of 30 mins
		   	'automatic_serialization' => true);
		
$backendOptions = array(
		    	// Directory where to put the cache files
		    	'cache_dir' => '/cache/' 
			);

// getting a Zend_Cache_Core object
$cache = Zend_Cache::factory('Core','File', $frontendOptions, $backendOptions);

if (!$rss = $cache->load($cacheId)) {
	try {
		$rss = Zend_Feed::import($rssFeedLink);
	} catch (Exception $e) {
		$feedError = true;
	}
	
	//check to see if it did not fail
	if (!$feedError && is_object($rss))
	{
		$cache->save($rss, $cacheId);	
	}
}

//assuming that everything went right while fetching the feed
foreach ($rss as $item) {
	$channel['items'][] = array(
		'title'       => $item->title(),
		'link'        => $item->link(),
		'description' => $item->description()
	);
}

read more