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

Caching action and main separately

Hey guys,

I've been playing with the view cache based on albumorama and default devtools scaffolding. One thing I've notices, is that the view cache caches the entire 'view' - action and main layouts. Is it possible to separate those, so only the /views/media/index.volt would get cached?

function indexAction() {      
        $key = 'media-index-all-latest';
        $exists = $this->view->getCache()->exists($key);                
        if( !$exists) {            
            $this->view->setVar('time', time());       
        }   
        $this->view->cache(
            array(  "lifetime" => 86400, "key"  => $key, )
        );                                       
    }  

Thanks



98.9k

You can set the cache level as an option:

$this->view->cache(array("lifetime" => 86400, "key"  => $key, "level" => Phalcon\Mvc\View::LEVEL_ACTION_VIEW));


15.1k

I've tried that, and it still saves the entire page to the cache file. Could there be something else I may have accidentally changed?



98.9k

Try deleting your cache to force a cache regeneration



15.1k

Tried it. Tested with File backend and my own Wincache implementation and the same problem occurs.