Clear specific views using clearCache(); in CakePHP 2.0
clearCache();
The above will clear all file in /tmp/cache/views
clearCache($params = 'index', $type = 'views', $ext = '.php');
The above will clear the view file in /tmp/cache/views/ named index.php
clearCache($params = array('home', 'index' 'contact'), $type = 'views', $ext = '.php');
The above will clear the view files in /tmp/cache/views/ named home.php/index.php/contact.php
$params can be set as an array of filenames you would like to clear.
You can also set $params to data being parsed through the model like so
clearCache($params = $this->data['Posts']['path'], $type = 'views', $ext = '.php');
Using the above under the function afterSave will clear the last saved posts view cache. This can be adapted to work will different aspects of the data parsing through the model.
You can also use wildcards * like so
clearCache( array($params = array('services*'), $type = 'views', $ext = '.php'));
The above will clear all cached views starting with services.
Written by Matt Stephens
Related protips
1 Response
Very helpful, more explicative than official documentation. Thank you
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Mvc
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#