We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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.

Disable cache vor view in dev environment

Hi,

I'm just searching for a way to disable .volt files cache for my dev environment.

Because everytime i modify a .volt file template, i have to 'rm app/cache/*'

Thanks



40.7k
Accepted
answer

Try this, or modify for your needs:

$di->set('view', function(){
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/views/');

        $view->registerEngines(array(
            '.volt' => function($view, $di) {
            $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);
            $volt->setOptions(array(
              'compiledPath' => '../app/compiled/',
              'stat' => true,
              'compileAlways' => true  
            ));
            return $volt;
            }
        ));

    return $view;
});

sometimes better solution is not to overcomplicate framework and use additional software, like incron: http://www.pablumfication.co.uk/2010/09/23/incron-file-system-event-monitoring/ http://inotify.aiken.cz/?section=incron&page=doc&lang=en and when you update your .volt template, incron could 'rm app/cache/*' :)

If you need recursive incron, there is watcher: http://www.splitbrain.org/blog/2011-01/07-watcher_a_recursive_incron_alternative

Thanks @doit76 ! This is an usefull information :)

I solved it like this.

I added another parameter to config

'settings' => [
        'development'    => TRUE,
    ]

Then I just check for the parameter where the view component is setup to disable the cache completly while in development mode

$di->setShared('view', function () {
    $config = $this->getConfig();

    $view = new View();
    $view->setDI($this);
    $view->setViewsDir($config->application->viewsDir);

    $view->registerEngines([
        '.volt' => function ($view) {
            $config = $this->getConfig();

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

            if($config->settings->development === false) {
                $volt->setOptions([
                    'compiledPath' => $config->application->cacheDir,
                    'compiledSeparator' => '_',
                    'compileAlways' => true
                ]);
            }
            return $volt;
        },
        '.phtml' => PhpEngine::class // php >= 5.5 only
        //'.phtml' => 'Phalcon\Mvc\View\Engine\Php' // php <= php 5.4 work-around

    ]);

    return $view;
});

Another solution is found here: https://forum.phalcon.io/discussion/1386/how-to-disable-cache-in-volt-when-development Where a person named Jason solved it by unlinking files and forcing volt to always compile the files