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

Volt caching for view fragments does not work with safekey option

Hi all,

Base on https://docs.phalcon.io/en/latest/reference/volt.html#caching-view-fragments section of document, I've use cache functionality in my volt script:

{% cache "categories" %}
    {% for index, category in categories %}
         //  blah blah
    {% endfor %}
{% endcache %}

and in my vlot service, I'm using safekey option for viewCache service as follow:

$di->set(
    'viewCache',
    function() {
        $front = PhCacheFront([
            'lifetime' => '1296000'
        ]);

        return PhCacheBack([
            'cachDir' => '/cache',
            'prefix' => 'view.',
            'safekey' => true
        ]);
    }
);

But, It seams Volt's cache tag does not folow keyGenerator approeach and uses an array with pure defined key in script!

This is my compiled volt script:

...
$_cache['categories'] = $this->di->get('viewCache');
$_cacheKey['categories'] = $_cache['categories']->start('categories'); 
if ($_cacheKey['categories'] === null) {  // <-- This check is wrong
...

I think volt's cache system shoud be smarter and check $_cacheKey with safekey option in mind.

Any idea or workaround?

Thanks.



14.8k
Accepted
answer

Oops! Sorry for my mistake! It's my bad configuration.

I think everything with volt's cache functionality is OK.

Thanks.