2
votes

I'm using Zend Framework & Zend_Paginator with Doctrine 2 and DoctrineExtensions Paginate Adapter.

I need to cache my result, however, I don't know where should I do this.

It seems logical to me to do it in the Repository, but I tried and it doesn't work with the paginator adapter.

How would you go?

1

1 Answers

0
votes

Check out Zend_Cache. There are a handful of different adapters including file, database, and memcached - but the general way of handling it is this:

$frontendOptions = array(
   'lifetime' => 7200, // cache lifetime of 2 hours
   'automatic_serialization' => true
);

$backendOptions = array(
    'cache_dir' => './tmp/' // Directory where to put the cache files
);

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

if( ($result = $cache->load('myresult')) === false ) {
  // fetch $result
  $cache->save($result, 'myresult');
}

$result is not a cached var.