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 cache in volt when development

Hi all I use template engine, but when development cache has been create, i want to disable,


You can set a config variable say "debug" and based on that compile the templates or not.

Have a look at this


                        if ('1' != $config->application->debug) {
                            $voltOptions['compileAlways'] = true;

compileAlways for volt means no cache


Thank you,I ask, how to display code as above

I ran into a problem with this as well. Very ocassionally, Volt will fail to realize that a template file has changed, which can be frustrating in dev when you're changing things constantly. I solved it by adding this block to my service definition.

 * Clear out the Volt cache dir on every request in debug mode.
 * Volt appears to have no capacity to compile itself to memory; it always
 * needs to write its output to file and sometimes the engine doesn't
 * realize that a template has changed, so it doesn't re-compile it.
if ($config->application->debugMode) {
  array_map('unlink', glob($config->application->cacheDir . 'volt/*.php'));
    'compileAlways' => TRUE,
edited Feb '18

The accepted answer is great, I am just using bool for my config, as perhaps many of you are - explicit / positive

$volt = new VoltEngine($view, $this);

$voltOptions = [
  'compiledPath' => $config->application->cacheDir . 'volt/',
  'compiledSeparator' => '_'

if ($config->application->debug === true) {
    $voltOptions['compileAlways'] = true;