Home | 简体中文 | 繁体中文 | 杂文 | Search | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 作品与服务 | Email

9.4. cache

9.4.1. Redis 缓存

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

9.4.2. 多种缓存混合使用

多个缓存同事使用,我们借助 $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;
	});
			
			
comments powered by Disqus