Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Volt caching for view fragments does not work with safekey option

Hi all,

Base on http://docs.phalconphp.com/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.



7.0k
Accepted
answer

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

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

Thanks.