How to disable volt cache

I have followed this simple example https://docs.phalconphp.com/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 );


6.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.phalconphp.com/en/latest/reference/volt.html#setting-up-the-volt-engine



36.5k

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.