We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

viewCache don`t work

Hi all. I have trouble with viewCache.

In config.php i have next config for cach folder.

'cacheDir'            => APP_PATH . '/app/cache/',

It`s work fine for volts and metaData files.

My servises.php:

use Phalcon\Cache\Frontend\Output as OutputFrontend;
use Phalcon\Cache\Backend\File as FileBackend;
...........................

//Set the views cache service
$di->set('viewCache', function () use ($config) {

    $frontCache = new OutputFrontend(
        array(
            "lifetime" => 86400
        )
    );

    //Set the cache directory
    $backendOptions = array(
        'cacheDir' => $config->application->cacheDir . 'view/',
    );

    $cache = new FileBackend(
        $frontCache,
        $backendOptions
    );

    return $cache;
});

folder 'view' created and writable.

In my controller I have next action:


   public function showAction($post_id, $slug)
    {
        $exists = $this->view->getCache()->exists($post_id.$slug);
        // var_dump($exists); exit; // I`ts return false
        if (!$exists) {
            $post = Posts::findFirst($post_id);

            if (!$post) {
                $this->flash->error("The Post not exist!");
                return $this->response->redirect('/post/index');
            }

            // +1 to view counter
            $post->PostsViews->incrementByOne();

            $this->assets
                ->collection('css-acticle-blog')
                ->addCss('blog/css/article.css');

            $this->view->setVar('show_slider', false);
            $this->view->setVar('show_post', true);
            $this->view->setVar('post', $post);
            $this->tag->prependTitle($post->title);
        }

        $this->view->cache(array("lifetime" => 86400, "key" => $post_id.$slug));
    }

Files in view folder not created. What I do wrong and have make this working?

edited Jan '16

In my controller I use next render level:

$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);

And My views file look like this:

Main layout blog.volt

-------------------
{% block content %}
{% endblock %}
------------------

and action file:

{% extends "blog.volt" %}

{% block content %}
// html code here
{% endblock %}

Can this produce a problem?



1.3k
Accepted
answer

Yes, I commented this line:

// $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);

And caching start working.