[英]How to flush frontend Cache from backend in Yii2
I am using YII2 Advanced, on the backend I needed an Action that invalidates the Cache in the frontend. 我正在使用YII2 Advanced,在后端我需要一个Action,它使前端的Cache无效。
This is needed because I use yii2mod/yii2-settings , obiously, the settings are being cached on both ends. 这是必需的,因为我使用yii2mod / yii2设置 ,很明显,设置正在两端缓存。 But I wasn't able to flush the cache from the backen with
Yii::$app->cache->flush();
但是我无法使用
Yii::$app->cache->flush();
来从后台刷新缓存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. 所以我发现如果我在后端组件上做一个引用,我终于可以访问后端的flush。
On \\backend\\config\\main.php
在
\\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. 我花了一段时间才弄明白这一点,所以我希望这对某人有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.