Why doesn't Cache :: clear () clear my (view) cache? (CakePHP)

Although documented , CakePHP will automatically clear view caches when updating the model, it is not.

It is important to remember that Cake will clear the cached view if the model used in the cached view is changed. For example, if the cached view uses data from the Post model and an INSERT, UPDATE, or DELETE request has been added to the message, the cache for this view is cleared and new content is generated the next time it is requested.

Even calling the proposed method Cache::clear()manually does nothing. How to clear view cache in Cake?

(Starting with the version 1.2.2.8120. Looking at the repository, it should have such a problem .8256.)

+3
source share
2 answers

Use clearCache()perhaps automatically in the model callback afterSave:

// model file:
function afterSave($created) {
    clearCache();
}

(Please also document other available solutions, this is the only one I could find.)

+3
source

use Cache :: clearCache (); or delete exactly the file that you do not want to delete

function afterSave($created)
{
  parent::afterSave(false);
  Cache::delete('left_menu_eng');
}
0
source

Source: https://habr.com/ru/post/1713561/


All Articles