views:

80

answers:

3

Hi, I am using Zend Cache with page caching but it seems to miss the cache after a period of time. For a while it is OK, but I come back tomorrow and hit the page, it doesn't fetch the contents from the cache. why?

$frontendOptions = array(
    'content_type_memorization' => true, // This remembers the headers, needed for images
   'lifetime' => NULL,                   // cache lifetime forever
   'automatic_serialization' => true,
   'automatic_cleaning_factor' => 0
);

$myPageCache = new Zend_Cache_Frontend_Page(array(
    'debug_header' => false,
    'automatic_cleaning_factor'=>0,
    'content_type_memorization' => true,
    'default_options'           => array(
    'cache' => true,
    'cache_with_get_variables' => true,
    'cache_with_post_variables' => true,
    'cache_with_session_variables' => true,
    'cache_with_cookie_variables' => true
    )));


$backendOptions = array('cache_dir' => '.' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR);

$cache = Zend_Cache::factory($myPageCache,
                             'File',
                             $frontendOptions,
                             $backendOptions);

$cacheKey = hash('md5', "cache_" . $cachePath); // cachePath is the key I use for the cache

if(!$cache->start($cacheKey)) {
I output html here
 $cache->end();
}
A: 

ahh... opps.

Is it because my 'lifetime' => NULL, is being ignored?

Phil
+1  A: 

Indeed. My read of the static method

Zend_Cache::factory($frontend, $back, $frontendOptions, $backendOptions, ...) 

is that the $frontendOptions are used only when you pass a string for the $frontend parameter. When you pass a concrete instance as you are doing, the $frontendOptions are ignored.

If you still want to pass a concrete instance $myPageCache into the factory, then it seems like you need to pass the lifetime parameter (and the others) into the call that creates the instance. Otherwise, you could load up a single $frontendOptions array and use:

$cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
David Weinraub
A: 

Hi people!

I have similar problem with my page cache, I am initializing it in Bootstrap file and it works on my machine (local server) but when I upload it on the remote server it creates cache files but it doesn't read it, I see that there is no debug header meaning that pages are loading all over again. I don't know what to do and I'm really desperate about this. Please give me an idea if you have any :(

Here is my code:

        $frontendOptions = array(
'lifetime' => 3600,
      'debug_header' => true,
'default_options' => array(
          'cache_with_get_variables' => true,
          'cache_with_post_variables' => true,
          'cache_with_session_variables' => true,
          'cache_with_files_variables' => true,
          'cache_with_cookie_variables' => true,
          'make_id_with_get_variables' => true,
          'make_id_with_post_variables' => true,
          'make_id_with_session_variables' => true,
          'make_id_with_files_variables' => true,
          'make_id_with_cookie_variables' => true,
),
'regexps' => array(
           '^/$' => array('cache' => true)
)

); $dir = APPLICATION_PATH . DIRECTORY_SEPARATOR . 'cache'; $backendOptions = array( 'cache_dir' => $dir );

     $cache = Zend_Cache::factory(
      'Page',
      'File',
      $frontendOptions,
      $backendOptions
     );

     $cache->start();
     //Zend_Registry::set('cache',$cache);
milica