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

How to disable volt cache

I have followed this simple example https://docs.phalcon.io/en/latest/reference/volt.html#partial-vs-include it generate base.html%%e%%.tpl how to disable generation of these compiled files ?

$compiler = new \Phalcon\Mvc\View\Engine\Volt\Compiler();
$compiler->setOption( 'compiledExtension', '.tpl' );
$compiler->setOption( 'compileAlways', true ); //not working, it still creates tpl file

$tpl = file_get_contents( BASE_DIR . '/layouts/main.html' );
$str = $compiler->compileString( $tpl );


12.2k

You pass an option to volt instance.

use Phalcon\Mvc\View\Engine\Volt as VoltEngine;

// This I setup in view service
$volt = new VoltEngine($view, $di);

// Add volt options
$volt->setOptions(
    [
        'compileAlways'     => true,
    ]
);

Manual: https://docs.phalcon.io/en/latest/reference/volt.html#setting-up-the-volt-engine



58.3k

Hey man

When you disable volt cache it mean the volt allway a new file, so that is true

It's not cache. It's generated view. Volt it's only some language that provides you easier way to handling views. But it must be generated to some file, beacause is generating plain php and it needs to be stored somewere.

I would just like to add that for production is good to disable this flag, so the VOLT engine will not recompile from volt -> php native every time, while your output generated native php views will be cached by OPcache. I found out also that even with compileAlways disabled, if you change your child template Volt will recompile it. It's just then you have to wait for OPcache to catch it, or manually to restart OPcache pool / specific file from the pool.

@stamster

What you mean ? I recommend on dev machine just to set opcache to validate timestamps.

Wojciech, no issues with your comment(s) at all! I'm just providing my recent expirience with Phalcon -> Volt -> OPcache for production env. It's nice to know.

edited Jul '20

Important note to everybody who was searching for this:

I have Phalcon 4.0.6 running and get

Deprecated: The 'compileAlways' option is deprecated. Use 'always' instead.

So it changed:


$volt->setOptions(
    [
        'always'     => true,
    ]
);

Also manual changed a bit: https://docs.phalcon.io/en/latest/reference/volt.html#activation

Greets Marco