增加 APCu缓存

This commit is contained in:
Discuz! 2017-02-04 10:54:17 +08:00
parent 2b7f948ec6
commit 0ba78f6b31
5 changed files with 92 additions and 36 deletions

View File

@ -4,7 +4,7 @@
* [Discuz!] (C)2001-2099 Comsenz Inc. * [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms * This is NOT a freeware, use is subject to license terms
* *
* $Id: config_global_default.php 36287 2016-12-12 03:59:05Z nemohou $ * $Id: config_global_default.php 36362 2017-02-04 02:02:03Z nemohou $
*/ */
$_config = array(); $_config = array();
@ -111,7 +111,8 @@ $_config['memory']['memcache']['port'] = 11211; // memcache 服务器端口
$_config['memory']['memcache']['pconnect'] = 1; // memcache 是否长久连接 $_config['memory']['memcache']['pconnect'] = 1; // memcache 是否长久连接
$_config['memory']['memcache']['timeout'] = 1; // memcache 服务器连接超时 $_config['memory']['memcache']['timeout'] = 1; // memcache 服务器连接超时
$_config['memory']['apc'] = 1; // 启动对 apc 的支持 $_config['memory']['apc'] = 1; // 启动对 APC 的支持
$_config['memory']['apcu'] = 1; // 启动对 APCu 的支持
$_config['memory']['xcache'] = 1; // 启动对 xcache 的支持 $_config['memory']['xcache'] = 1; // 启动对 xcache 的支持
$_config['memory']['eaccelerator'] = 1; // 启动对 eaccelerator 的支持 $_config['memory']['eaccelerator'] = 1; // 启动对 eaccelerator 的支持
$_config['memory']['wincache'] = 1; // 启动对 wincache 的支持 $_config['memory']['wincache'] = 1; // 启动对 wincache 的支持

View File

@ -4,7 +4,7 @@
* [Discuz!] (C)2001-2099 Comsenz Inc. * [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms * This is NOT a freeware, use is subject to license terms
* *
* $Id: admincp_setting.php 36349 2017-01-16 03:05:23Z nemohou $ * $Id: admincp_setting.php 36362 2017-02-04 02:02:03Z nemohou $
*/ */
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) { if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')) {
exit('Access Denied'); exit('Access Denied');
@ -2247,6 +2247,11 @@ EOT;
$cache_config['yac'] ? cplang('open') : cplang('closed'), $cache_config['yac'] ? cplang('open') : cplang('closed'),
$cache_type == 'yac' ? $do_clear_link : '--' $cache_type == 'yac' ? $do_clear_link : '--'
); );
$apcu = array('APCu',
$cache_extension['apcu'] ? cplang('setting_memory_php_enable') : cplang('setting_memory_php_disable'),
$cache_config['apcu'] ? cplang('open') : cplang('closed'),
$cache_type == 'apcu' ? $do_clear_link : '--'
);
showtablerow('', array('width="100"', 'width="120"', 'width="120"'), $redis); showtablerow('', array('width="100"', 'width="120"', 'width="120"'), $redis);
showtablerow('', '', $memcache); showtablerow('', '', $memcache);
showtablerow('', '', $apc); showtablerow('', '', $apc);
@ -2254,6 +2259,7 @@ EOT;
showtablerow('', '', $ea); showtablerow('', '', $ea);
showtablerow('', '', $wincache); showtablerow('', '', $wincache);
showtablerow('', '', $yac); showtablerow('', '', $yac);
showtablerow('', '', $apcu);
showtablefooter(); showtablefooter();
if(!isset($setting['memory'])) { if(!isset($setting['memory'])) {

View File

@ -4,7 +4,7 @@
* [Discuz!] (C)2001-2099 Comsenz Inc. * [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms * This is NOT a freeware, use is subject to license terms
* *
* $Id: discuz_memory.php 31432 2012-08-28 03:04:18Z zhangguosheng $ * $Id: discuz_memory.php 36362 2017-02-04 02:02:03Z nemohou $
*/ */
if(!defined('IN_DISCUZ')) { if(!defined('IN_DISCUZ')) {
@ -29,8 +29,8 @@ class discuz_memory extends discuz_base
$this->extension['xcache'] = function_exists('xcache_get'); $this->extension['xcache'] = function_exists('xcache_get');
$this->extension['eaccelerator'] = function_exists('eaccelerator_get'); $this->extension['eaccelerator'] = function_exists('eaccelerator_get');
$this->extension['wincache'] = function_exists('wincache_ucache_meminfo') && wincache_ucache_meminfo(); $this->extension['wincache'] = function_exists('wincache_ucache_meminfo') && wincache_ucache_meminfo();
$this->extension['xcache'] = function_exists('xcache_get');
$this->extension['yac'] = extension_loaded('Yac'); $this->extension['yac'] = extension_loaded('Yac');
$this->extension['apcu'] = function_exists('apcu_cache_info') && @apcu_cache_info();
} }
public function init($config) { public function init($config) {
@ -54,7 +54,7 @@ class discuz_memory extends discuz_base
} }
} }
foreach(array('apc', 'eaccelerator', 'xcache', 'wincache','yac') as $cache) { foreach(array('apc', 'eaccelerator', 'xcache', 'wincache', 'yac', 'apcu') as $cache) {
if(!is_object($this->memory) && $this->extension[$cache] && $this->config[$cache]) { if(!is_object($this->memory) && $this->extension[$cache] && $this->config[$cache]) {
$class_name = 'memory_driver_'.$cache; $class_name = 'memory_driver_'.$cache;
$this->memory = new $class_name(); $this->memory = new $class_name();

View File

@ -0,0 +1,51 @@
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: memory_driver_apc.php 27635 2012-02-08 06:38:31Z zhangguosheng $
*/
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class memory_driver_apcu {
public function init($config) {
}
public function get($key) {
return apcu_fetch($key);
}
public function getMulti($keys) {
$result = array();
foreach($keys as $key) {
$result[$key] = apcu_fetch($key);
}
return $result;
}
public function set($key, $value, $ttl = 0) {
return apcu_store($key, $value, $ttl);
}
public function rm($key) {
return apcu_delete($key);
}
public function clear() {
return apcu_clear_cache('user');
}
public function inc($key, $step = 1) {
return apcu_inc($key, $step) !== false ? apcu_fetch($key) : false;
}
public function dec($key, $step = 1) {
return apcu_dec($key, $step) !== false ? apcu_fetch($key) : false;
}
}

View File

@ -6,13 +6,11 @@
* *
* $Id: memory_driver_yac.php 27635 2017-02-02 17:02:46Z NaiXiaoxIN $ * $Id: memory_driver_yac.php 27635 2017-02-02 17:02:46Z NaiXiaoxIN $
*/ */
if (!defined('IN_DISCUZ')) { if (!defined('IN_DISCUZ')) {
exit('Access Denied'); exit('Access Denied');
} }
class memory_driver_yac class memory_driver_yac {
{
private $object = null; private $object = null;