1、修改/framework/function/cache.func.php 的 cache_type函数:
function cache_type()
{
global $_W;
$cacher = $connect = '';
$cache_type = strtolower($_W['config']['setting']['cache']);
if ($cache_type == 'memcached') return $cache_type;
if (extension_loaded($cache_type)) {
$config = $_W['config']['setting'][$cache_type];
if (!empty($config['server']) && !empty($config['port'])) {
if ('memcache' == $cache_type) {
$cacher = new Memcache();
}
elseif ('redis' == $cache_type) {
$cacher = new Redis();
}
$connect = $cacher->connect($config['server'], $config['port']);
}
}
if (empty($cacher) || empty($connect)) {
$cache_type = 'mysql';
}
return $cache_type;
}
2、新增函数文件
/framework/function/cache.memcached.func.php
内容:
<?php
defined('IN_IA') or exit('Access Denied');
function cache_memcached()
{
global $_W;
static $memcacheobj;
if (!extension_loaded('memcached')) {
return error(1, 'Class Memcache is not found');
}
if (empty($memcacheobj)) {
$config = $_W['config']['setting']['memcached'];
$memcacheobj = new Memcached;
$memcacheobj->setOption(Memcached::OPT_COMPRESSION, false);
$memcacheobj->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$memcacheobj->setOption(Memcached::OPT_TCP_NODELAY, true);
if (empty($config['port'])) $config['port'] = 11211;
if (!empty($config['server'])) {
$memcacheobj->addServer($config['server'], $config['port']);
}
else {
return error(1, 'Server info in the config file not found.');
}
if (!empty($config['user']) and !empty($config['password'])) {
$memcacheobj->setSaslAuthData($config['user'], $config['password']);
}
}
return $memcacheobj;
}
function cache_read($key, $forcecache = true)
{
$key = cache_namespace($key);
$memcache = cache_memcached();
if (is_error($memcache)) {
return $memcache;
}
$result = $memcache->get(cache_prefix($key));
if (empty($result) && empty($forcecache)) {
$dbcache = pdo_get('core_cache', array(
'key' => $key
) , array(
'value'
));
if (!empty($dbcache['value'])) {
$result = iunserializer($dbcache['value']);
$memcache->set(cache_prefix($key) , $result, 0);
}
}
return $result;
}
function cache_search($key)
{
return cache_read(cache_prefix($key));
}
function cache_write($key, $value, $ttl = 0, $forcecache = true)
{
$key = cache_namespace($key);
$memcache = cache_memcached();
if (is_error($memcache)) {
return $memcache;
}
if (empty($forcecache)) {
$record = array();
$record['key'] = $key;
$record['value'] = iserializer($value);
pdo_insert('core_cache', $record, true);
}
if ($memcache->set(cache_prefix($key) , $value, 0)) {
return true;
}
else {
return false;
}
}
function cache_delete($key, $forcecache = true)
{
$origins_cache_key = $key;
$key = cache_namespace($key);
$memcache = cache_memcached();
if (is_error($memcache)) {
return $memcache;
}
if (empty($forcecache)) {
pdo_delete('core_cache', array(
'key' => $key
));
}
if ($memcache->delete(cache_prefix($key))) {
unset($GLOBALS['_W']['cache'][$origins_cache_key]);
return true;
}
else {
unset($GLOBALS['_W']['cache'][$origins_cache_key]);
return false;
}
}
function cache_clean($prefix = '')
{
if (!empty($prefix)) {
$cache_namespace = cache_namespace($prefix, true);
unset($GLOBALS['_W']['cache']);
pdo_delete('core_cache', array(
'key LIKE' => $cache_namespace . '%'
));
return true;
}
$memcache = cache_memcached();
if (is_error($memcache)) {
return $memcache;
}
if ($memcache->flush()) {
unset($GLOBALS['_W']['cache']);
pdo_delete('core_cache');
return true;
}
else {
return false;
}
}
function cache_namespace($key, $forcenew = false)
{
if (!strexists($key, ':')) {
$namespace_cache_key = $key;
}
else {
list($key1, $key2) = explode(':', $key);
if ($key1 == 'we7') {
$namespace_cache_key = $key2;
}
else {
$namespace_cache_key = $key1;
}
}
if (!in_array($namespace_cache_key, array(
'unimodules',
'user_modules'
))) {
return $key;
}
$namespace_cache_key = 'cachensl:' . $namespace_cache_key;
$memcache = cache_memcached();
if (is_error($memcache)) {
return $memcache;
}
$namespace = $memcache->get(cache_prefix($namespace_cache_key));
if (empty($namespace) || $forcenew) {
$namespace = random(5);
$memcache->set(cache_prefix($namespace_cache_key) , $namespace, 0);
}
return $namespace . ':' . $key;
}
function cache_prefix($key)
{
return $GLOBALS['_W']['config']['setting']['authkey'] . $key;
}
3、其他修改地方
忽略····
管理员将状态修改为{{statusText(item.status)}} {{item.system == 1?'管理员':'微擎用户'}} {{item.created_at}}