配置 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; });