这是我在Yii 1.x应用程序中添加到config/main.php
的代码:
'mCache' => array(
'class' => 'system.caching.CMemCache',
'useMemcached'=>true,
'keyPrefix'=>'',
'hashKey'=>false,
'serializer'=>false,
'servers' => array(
array('host' => '127.0.0.1', 'port' => 11211, 'weight' => 10000)
),
),
'session' => array(
'sessionName' => 'PHPSESSID',
'class' => 'CCacheHttpSession',
'autoStart' => true,
'cacheID' => 'mCache',
'cookieMode' => 'only',
'timeout' => 1200
),
下一步,我该如何强制Yii使用CMemCache
,而不是默认的会话存储?
我知道这个答案很旧,但是这种配置有效
'memcacheConn'=>array(
'class'=>'CMemCache',
'servers'=>array(
array(
'host'=>'172.17.0.1',
'port'=>11211,
//'weight'=>60,
),
),
),
'session' => array(
'class' => 'CCacheHttpSession',
'autoStart' => true,
'cacheID' => 'memcacheConn',
'cookieMode' => 'allow',
'sessionName' => 'MYSSIONNAME',
),
您是否阅读了Yii 1.x API文档中的CMemCache
简介?我想你没有。在本文档的第一段中,您有一个示例,说明如何在Yii 1.x中使用CMemCache
。
'class'=>'CCacheHttpSession'
更改为'class'=>'CMemCache'
。而且您不必像在示例中一样将session
注册为单独的组件(CMemCache
)。您可以直接在mCache
配置密钥中对其进行配置。[C0中的示例:
session