我想在Yii中使用标签缓存。
但事实证明,前端使用它的缓存后端。当我在后端更改模型时,缓存的前端不会被清除。有什么解决办法吗?
对不起,我的英语不好。
在各自的配置文件中为前端和后端设置不同的缓存前缀。
我仍然使用1.1。X分支,但是2。X分支应该是一样的
前端配置文件:
'cache' => array(
'class' => 'system.caching.' . (!MW_DEBUG ? 'CFileCache' : 'CDummyCache'),
'keyPrefix' => md5('frontend.' . MW_VERSION . Yii::getPathOfAlias('frontend')),
),
后台配置文件:
'cache' => array(
'class' => 'system.caching.' . (!MW_DEBUG ? 'CFileCache' : 'CDummyCache'),
'keyPrefix' => md5('backend.' . MW_VERSION . Yii::getPathOfAlias('backend')),
),
在我的情况下,在DI中缓存服务的运行时,对于FileCache,设置另一个cachePath也很好。
//in backend
$cache = 'Yii::$app->cache;
if ($cache instanceof FileCache) {
$cache->cachePath = 'Yii::getAlias('@frontend/runtime/cache');
$cache->set('my_cache_prefix', $myData);
}
//This way I have overridden expired cache in frontend