配置 Redis 缓存
//Set the models cache service
$di->set('cache', function() use ($config) {
//Cache data for one day by default
$frontCache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime" => 86400
));
//Create the Cache setting redis connection options
$cache = new Phalcon\Cache\Backend\Redis($frontCache, array(
'host' => $config->redis->host,
'port' => $config->redis->port,
'auth' => $config->redis->auth,
'persistent' => true,
/*'statsKey' => 'info',*/
'index' => 1 /*选择redis数据库*/
));
return $cache;
});
多个缓存同事使用,我们借助 $cache = new stdClass(); 将多种缓存 $cache->redis 与 $cache->file 同时返回
//Set the models cache service
$di->set('cache', function() use ($config) {
//Cache data for one day by default
$frontCache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime" => 86400
));
//Create the Cache setting redis connection options
$redis = new Phalcon\Cache\Backend\Redis($frontCache, array(
'host' => $config->redis->host,
'port' => $config->redis->port,
// 'auth' => $config->redis->auth,
// 'persistent' => true,
// 'statsKey' => 'info',
'index' => 1
));
$frontCache = new \Phalcon\Cache\Frontend\Data(array(
"lifetime" => 86400
));
$file = new \Phalcon\Cache\Backend\File($frontCache, array(
"cacheDir" => "../app/cache/"
));
$cache = new stdClass();
$cache->redis = $redis;
$cache->file = $file;
//$cache->mem = $mem;
return $cache;
});