1

我正在使用控制台应用程序为我的应用程序创建缓存。但我无法为我的网络应用程序共享该缓存。(在我的 Redis 数据库中,它的显示是从控制台创建的)知道如何将从控制台创建的缓存共享到我的 Web 应用程序吗?

4

2 回答 2

3

I was getting same issue which was resolved by keeping same setting for backend and frontend both apps.

'cache'=> array(
    'class' => 'CRedisCache',
    'hostname' => 'localhost',
    'port' => 6379,
    'database' => 0,
    'hashKey' => false,
    'keyPrefix' => '',
);

set keyPrefix to empty and hashKey to false,

if you use default setting for keyPrefix and hashKey CRedisCache will create different keys for same value provided from set command eg.

 Yii::app()->cache->set('foo', 'bar'); frontend server 
will create key in redis something like "0327f5f7378e9056c775ab69aa206322"

  Yii::app()->cache->set('foo', 'bar'); backend server 
ll create key in redis something like "d2c81df2db2285435c1975b5cb5c5b66"      

CRedisCache creates unique key by using combination of hashKey and keyPrefix for every requested server.

于 2016-04-15T13:09:48.213 回答
0

前端配置文件:

'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('console.' . MW_VERSION . Yii::getPathOfAlias('backend')),
),

参考答案

于 2014-09-24T12:17:12.923 回答