$cache_key = 'user_123'; $user = $this->User->findById(123); // invalidate cache for the specific record $this->User->invalidate($cache_key);
// invalidate cache for all records $this->User->invalidateAll();
$query = $this->User->find('all', [ 'conditions' => ['active' => 1], 'cache' => ['key' => 'active_users', 'duration' => 3600] ]); // invalidate cache for the specific query $this->User->invalidate('active_users');In this example, we are using the cache option to cache the active users query result for an hour. You can then use the invalidate method to remove this specific cache. Package library: Yii ORM