简体   繁体   中英

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

Even though it's documented that CakePHP will automatically clear the view caches when a model is updated, it doesn't.

It is important to remember that Cake will clear a cached view if a model used in the cached view is modified. For example, if a cached view uses data from the Post model, and there has been an INSERT, UPDATE, or DELETE query made to a Post, the cache for that view is cleared, and new content is generated on the next request.

Even calling the suggested Cache::clear() method manually does nothing. How do I clear the view cache in Cake?

(As of version 1.2.2.8120 . Looking at the repository commits, even .8256 should have this problem.)

Use clearCache() , possibly automatically in a model afterSave callback:

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

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

use Cache::clearCache(); or delete exactly file you don't want to delete

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM