簡體   English   中英

單緩存前端和后端

[英]Single cache frontend and backend

我想在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM