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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With