memCache策略实现
memCache缓存允许将缓存保存到memCache内存缓存中. 提供对方访问接口如下: 它接收如下配置: array(
'security-code' => '', //继承自AbstractWindCache,安全码配置.
'key-prefix' => '', //继承自AbstractWindCache,缓存key前缀.
'expires' => '0', //继承自AbstractWindCache,缓存过期时间配置.
'compress' => '0', //压缩等级,默认为0
'servers' => array(
'host' => array(
'host'=>'localhost', //要连接的memcached服务端监听的主机位置.
'port'=>11211, //要连接的memcached服务端监听的端口.
'pconn'=>true, //控制是否使用持久化连接,默认true.
'weight' => 1, //为此服务器创建的桶的数量,用来控制此服务器被选中的权重,单个服务器被选中的概率是相对于所有服务器weight总和而言的.
'timeout' => 1, //连接持续(超时)时间(单位秒),默认值1秒.
'retry' => 15, //服务器连接失败时重试的间隔时间,默认值15秒.
'status' => true, //控制此服务器是否可以被标记为在线状态.
'fcallback' => null, //允许用户指定一个运行时发生错误后的回调函数
),
),
)
使用方法: 1、按照普通的调用类库的方式去调用:
$cache->setConfig(array('host' => 'localhost', 'port' => 11211));
$cache->set('name', 'test');
2、采用组件配置的方式,通过组件机制调用 在应用配置的components组件配置块中,配置memCache(该名字将决定调用的时候使用的组件名字): 'memCache' => array(
'path' => 'WIND:cache.strategy.WindMemCache',
'config' = array(
'security-code' => '',
'key-prefix' => '',
'expires' => '0',
'compress' => '0',
'servers' => array(
'host1' => array(
'host'=>'localhost',
'port'=>11211,
'pconn'=>true,
'weight' => 1,
'timeout' => 15,
'retry' => 15,
'status' => true,
'fcallback' => null,
),
),
),
),
如果含有多个memCache主机,可以设置多组host在config中,如host1,host2,其key值也可以自定义.<note>注意:要使用该组件需要安装memcache扩展库.</note> the last known user to change this file in the repository <LastChangedBy: xiaoxiao >
Located in /cache/strategy/WindMemCache.php [line 83]
WindModule
|
--AbstractWindCache
|
--WindMemCache
Author(s):
Information Tags:
|
Properties
|
Methods
|