with Zend_Cache. I've tested both pieces separately. I can successfully
cache something, and I can successfully retrieve my calendar data. However,
when I try to cache the calendar data I get errors about my foreach loop at
the end. I think it has to do with the serialization. However, it yells at
me if I turn the serialization to false. When I look at a print_r of what is
being cached it different from what is being pulled from
Zend_Gdata_Calendar.
Has anyone successfully done this before? Or can anyone help me figure out
where I've gone wrong? Below is my code.
require_once '../library/Zend/Cache.php';
$frontendOptions = array('lifetime' => 60, 'automatic_serialization' =>
true);
$backendOptions = array('cache_dir' => 'd:\temp\tmp');
$cache = Zend_Cache::factory('Core', 'File', $frontendOptions,
$backendOptions);
if( ($result = $cache->load('calendar')) === false) {
$startDate = date("Y-m-d", time());
$endDate = date("Y-m-d", time() + (14 * 24 * 60 * 60));
$user = 'myusername@gmail.com';
// get calendar stuff to result
require_once '../library/Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_Calendar');
$gdataCal = new Zend_Gdata_Calendar();
$query = $gdataCal->newEventQuery();
$query->setUser($user);
$query->setVisibility('public');
$query->setProjection('full');
$query->setOrderby('starttime');
$query->setSortorder('ascend');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
$result = $gdataCal->getCalendarEventFeed($query);
//save it to the cache
$cache->save($result, 'calendar');
}
else {
echo "This one is from cache!<br/></br>";
}
echo "<ul>\n";
foreach($result as $event) {
echo "\t<li>" . $event->title->text;
foreach($event->when as $when) {
echo " (" . date("M j g:ia", strtotime($when->startTime)) . ")\n";
}
echo "\t</li>\n";
}
echo "</ul>\n";
没有评论:
发表评论