缓存

框架提供了可基于filememcacheredis三种缓存类型,通过修改config/config.php进行设置,cache_type参数用于切换,完整示例如下:

// config/config.php
'cache' => array(
    'enable'     => true,
    'prefix'     => 'mc_df_',
    'cache_type' => 'redis',      // 缓存类型 file、memcache、redis
    'cache_time' => 7200,
    'cache_name' => 'cfc_data',
    'serialize' => true,          // 开启redis自动序列化存储
    'memcache' => array(
        'timeout' => 1,
        'servers' => array(
            array( 'host' => '127.0.0.1', 'port' => 11211, 'weight' => 1 ),
        )
    ),
    // redis目前只支持单台服务器
    'redis' => array(
        'timeout' => 30,
        'server' => array( 'host' => '127.0.0.1', 'port' => 6379, 'pass' => 'foobared')
    ),

    'session' => array(
        'type'   => 'cache',      // session 缓存类型 default、cache、mysql
        'expire' => 1440,         // session 回收时间 默认24分钟:1440、一天:86400
    )
)

Cache支持setgetdelttlincdec等简单操作方法

Cache还支持在知道使用何种缓存的时候使用其方法,比如driver是Redis,那么我们可以直接使用Redis的其他方法

Redis

当我们缓存没有使用Redis的情况下,但是又需要用到Redis的队列功能的时候,我们可以使用 cls_redis.php 类进行操作,配置请看上面的Cache中的Redis部分

Redis类不支持主从操作,但是支持多实例,所以在使用的时候可以通过不同配置创建多个实例来操作Redis

Last updated

Was this helpful?