Caching Calendar data with Zend_Cache

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Caching Calendar data with Zend_Cache

Josh Bates
I'm trying to cache the calendar data that I get from Zend_Gdata_Calendar
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 = '[hidden email]';
    // 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";
Reply | Threaded
Open this post in threaded view
|

Re: Caching Calendar data with Zend_Cache

Hector Virgen
>
> However, when I try to cache the calendar data I get errors about my
> foreach loop at the end.


What are the errors?

--
*Hector Virgen*
Sr. Web Developer
http://www.virgentech.com
--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: Caching Calendar data with Zend_Cache

Josh Bates
When I would do a print_r the first thing that it would put was
"__PHP_Incomplete_Class Object". I think I just figured out how to fix it. I
need to include the files for Zend_Gdata so it knows how to read the file
that is cached.

On Sun, Jan 30, 2011 at 7:59 PM, Hector Virgen <[hidden email]> wrote:

> However, when I try to cache the calendar data I get errors about my
>> foreach loop at the end.
>
>
> What are the errors?
>
> --
> *Hector Virgen*
> Sr. Web Developer
> http://www.virgentech.com
>