Answer the question
In order to leave comments, you need to log in
How to delete fragment cache in yii2?
In 1x the code does not work stupidly
$dependency = [
'class' => 'yii\caching\DbDependency',
'sql' => "SELECT updated_at FROM fm_competitions_matches WHERE id = {$round->id}"
];
if ($this->beginCache('Round'.$round->id, [
'duration' => 3600,
'dependency'=> $dependency,
])) {
// Кешируемый код
$this->endCache();
}
Yii::$app->cache->delete('Round'.$round->id);
Answer the question
In order to leave comments, you need to log in
I shoveled the framework code and found that the key for fragments is generated differently.
Solving the problem with clearing the fragment cache
$buldKey = ['yii\widgets\FragmentCache', 'Round'.$round->id];
Yii::$app->cache->delete($buldKey);
Why the dependence does not work immediately I do not know. It is not cleaned because the cache key for fragments is calculated automatically to prevent conflicts, like this:
https://github.com/yiisoft/yii2/blob/master/framew...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question