Answer the question
In order to leave comments, you need to log in
Yii2. Why doesn't TagDependency::invalidate() work?
Hello.
Please help me to deal with conditional caching (TagDependence) in Yii2. I am using memcached.
I want to cache the user's personal data (full name).
The logic is as follows:
1) in the UsersAuthComponent component, in the getUserById method, I set the cache by TagDependency.
public function getUserById($id)
{ // получить запись (ActiveRecord) пользователя User по id
return $this->getModel()::find()
->andWhere(['id' => $id])
->cache(null, new TagDependency(['tags' => 'current_user' . \Yii::$app->user->id]))
->one();
}
public function editUser($model)
{ // обновить данные пользователя
if (!$model->validate(['fio'])) {
return false;
}
if (!$model->update()) {
return false;
}
TagDependency::invalidate(\Yii::$app->cache, 'current_user'. \Yii::$app->user->id);
return true;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question