Zend_Cache_Frontend_Page no almacena en caché (no funcionó)

Buenos días,

I have run into some problem in the Zend_Cache_Frontend_Page. I want to use Zend_Cache_Frontend_Page to caching some of pages. But it does not work.

protected function _initBookPageCaching()
{
    Zend_Controller_Front::getInstance()->setParam('disableOutputBuffering',true);      
    // cache book pages
    $frontendOptionsPages = array(
       'lifetime' => 2592000,
       'debug_header' => true, // for debugging
       'regexps' => array(
           // cache the whole IndexController
           '^/$' => array('cache' => true),
           '^/download-free-ebook/.*' => array('cache' => true)
       )
    );

    $backendOptionsPages = array(
        'cache_dir' =>  APPLICATION_PATH.'/../cache'
    );

    $cacheBookPages = Zend_Cache::factory(
                         'Page',
                         'File',
                         $frontendOptionsPages,
                         $backendOptionsPages);

    $cacheBookPages->start();
}

i set above method into Bootstrap.php file.

Por favor ayudame a resolver este problema.

Gracias de antemano.

preguntado el 08 de noviembre de 11 a las 18:11

Is it creating a file in your cache directory? This will tell us if the cache is even being creado in the first place, let alone being used. -

no it does not create any file -

Ok gotcha, what is APPLICATION_PATH set to? Try echo APPLICATION_PATH . '/../cache'; and show me the results. -

3 Respuestas

Set application.ini

 resources.frontController.params.disableOutputBuffering = true

set bootstrap or action

$frontendOptions = array(
        'lifetime' => 900,
        'automatic_serialization' => 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,
            'cache'=>true
        ),


    );

    $backendOptions = array(
        'cache_dir' => APPLICATION_PATH . '/servercache/'
    );
    $cache = Zend_Cache::factory('Page', 'File', $frontendOptions, $backendOptions);
    $cache->start();

And here we go!!!!!!!!!!!!!!!!!!

Respondido 02 Abr '12, 16:04

I never actually use Zend_Controller_Front::getInstance() in my bootstrap, rather I use:

$this->bootstrap('frontController');

seguido por:

$front = $this->getResource('frontController');

with which you could try:

$front->setParam('disableOutputBuffering', true);

Also, I'm not sure what the acceptable regex's are for controllers and what not. Maybe try changing '^/download-free-ebook/.*' a '^/download-free-ebook/'. And see if just the index action for that controller at least caches.

EDIT: I found the issue. $cache->start(); is returning false so I did some debugging. You're not passing a cache id (e.g. $cacheBookPages->start('some_cache_id');) so Zend_Cache_Frontend_Page attempts to make one for you on line 261. like so:

// from Zend/Cache/Frontend/Page.php
public function start($id = false, $doNotDie = false)
{
    // ....
    if (!$id) {
        $id = $this->_makeId();
        if (!$id) {
            return false;
        }
    }
    // ....
}

So after following the rabbit trail, I realized that it was trying to build a cache id based off the following arrays: $_GET, $_POST, $_SESSION, $_COOKIE and $_FILES. Since none of those are set it is unable to create a cache id! And since it can't create a cache id, it can't create the cache file.

Solución:

$uri      = explode('/', $_SERVER['REQUEST_URI']);
$cacheKey = array();
foreach ($uri as $key) {
    if (empty($key)) {
        continue 1;
    }
    $cacheKey[] = $key;
}

$cacheBookPages->start('page_cache_' . implode('_', $cacheKey));

respondido 10 nov., 11:02

i have checked this changes but did not help. the URL is "/download-free-ebook/landscape-ecology" and this regex '^/download-free-ebook/.*' is works. - Mirodil

read my edit. I tried this very same code on mine and it worked! - Si Barry

Yes, regex may be wrong, especially slash may cause problems. Try to escape it by puting \ before each slash and if this not work, try to put everything in slashes like: '/^/download-free-ebook/.*/'

respondido 09 nov., 11:03

the URL is "/download-free-ebook/landscape-ecology" and this regex '^/download-free-ebook/.*' is works. - Mirodil

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.