ky_5yq
Last Updated: February 25, 2016
·
5.359K
· agentstephens

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.

1 Response
Add your response

16459

Very helpful, more explicative than official documentation. Thank you

over 1 year ago ·