Skip to content

Commit f0d854c

Browse files
committed
缓存驱动改进
1 parent 8e432eb commit f0d854c

3 files changed

Lines changed: 15 additions & 20 deletions

File tree

ThinkPHP/Library/Think/Cache/Driver/Memcached.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ public function __construct($options = array()) {
2929
}
3030

3131
$options = array_merge(array(
32-
'servers' => C('MEMCACHED_SERVER') ? C('MEMCACHED_SERVER') : null,
33-
'lib_options' => C('MEMCACHED_LIB') ? C('MEMCACHED_LIB') : null
32+
'servers' => C('MEMCACHED_SERVER') ? : null,
33+
'lib_options' => C('MEMCACHED_LIB') ? : null
3434
), $options);
3535

3636
$this->options = $options;

ThinkPHP/Library/Think/Cache/Driver/Memcachesae.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,21 @@ class Memcachesae extends Cache {
2727
* @access public
2828
*/
2929
function __construct($options=array()) {
30-
if(empty($options)) {
31-
$options = array (
32-
'host' => C('MEMCACHE_HOST') ? C('MEMCACHE_HOST') : '127.0.0.1',
33-
'port' => C('MEMCACHE_PORT') ? C('MEMCACHE_PORT') : 11211,
34-
'timeout' => C('DATA_CACHE_TIMEOUT') ? C('DATA_CACHE_TIMEOUT') : false,
30+
31+
$options = array_merge(array (
32+
'host' => C('MEMCACHE_HOST') ? : '127.0.0.1',
33+
'port' => C('MEMCACHE_PORT') ? : 11211,
34+
'timeout' => C('DATA_CACHE_TIMEOUT') ? : false,
3535
'persistent' => false,
36-
);
37-
}
36+
),$options);
37+
3838
$this->options = $options;
3939
$this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME');
4040
$this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX');
4141
$this->options['length'] = isset($options['length'])? $options['length'] : 0;
42-
// $func = isset($options['persistent']) ? 'pconnect' : 'connect';
4342
$this->handler = memcache_init();//[sae] 下实例化
4443
//[sae] 下不用链接
4544
$this->connected=true;
46-
// $this->connected = $options['timeout'] === false ?
47-
// $this->handler->$func($options['host'], $options['port']) :
48-
// $this->handler->$func($options['host'], $options['port'], $options['timeout']);
4945
}
5046

5147
/**

ThinkPHP/Library/Think/Cache/Driver/Redis.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,13 @@ public function __construct($options=array()) {
2626
if ( !extension_loaded('redis') ) {
2727
E(L('_NOT_SUPPORT_').':redis');
2828
}
29-
if(empty($options)) {
30-
$options = array (
31-
'host' => C('REDIS_HOST') ? C('REDIS_HOST') : '127.0.0.1',
32-
'port' => C('REDIS_PORT') ? C('REDIS_PORT') : 6379,
33-
'timeout' => C('DATA_CACHE_TIMEOUT') ? C('DATA_CACHE_TIMEOUT') : false,
29+
$options = array_merge(array (
30+
'host' => C('REDIS_HOST') ? : '127.0.0.1',
31+
'port' => C('REDIS_PORT') ? : 6379,
32+
'timeout' => C('DATA_CACHE_TIMEOUT') ? : false,
3433
'persistent' => false,
35-
);
36-
}
34+
),$options);
35+
3736
$this->options = $options;
3837
$this->options['expire'] = isset($options['expire'])? $options['expire'] : C('DATA_CACHE_TIME');
3938
$this->options['prefix'] = isset($options['prefix'])? $options['prefix'] : C('DATA_CACHE_PREFIX');

0 commit comments

Comments
 (0)