I am using YII2 Advanced, on the backend I needed an Action that invalidates the Cache in the frontend.
This is needed because I use yii2mod/yii2-settings , obiously, the settings are being cached on both ends. But I wasn't able to flush the cache from the backen with Yii::$app->cache->flush();
, this will do it just in the backend.
So somehow I found that if I make a reference on the backend components, I end having access to flush on the backend.
On \\backend\\config\\main.php
'components' => [
//...
'frontendCache' => [
'class' => 'yii\caching\FileCache',
'cachePath' => Yii::getAlias('@frontend') . '/runtime/cache'
],
]
Now in your controller
Yii::$app->cache->flush(); //backend flush
Yii::$app->frontendCache->flush(); //frontend flush
This took me a while to figure this out, so I hope this helps someone.
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.