新增 文件缓存,并安装后默认开启

This commit is contained in:
Discuz! 2017-02-09 15:24:36 +08:00
parent 5afd87a52f
commit abdc492b9a
2 changed files with 109 additions and 6 deletions

View File

@ -111,12 +111,13 @@ $_config['memory']['memcache']['port'] = 11211; // memcache 服务器端口
$_config['memory']['memcache']['pconnect'] = 1; // memcache 是否长久连接
$_config['memory']['memcache']['timeout'] = 1; // memcache 服务器连接超时
$_config['memory']['apc'] = 1; // 启动对 APC 的支持
$_config['memory']['apcu'] = 1; // 启动对 APCu 的支持
$_config['memory']['xcache'] = 1; // 启动对 xcache 的支持
$_config['memory']['eaccelerator'] = 1; // 启动对 eaccelerator 的支持
$_config['memory']['wincache'] = 1; // 启动对 wincache 的支持
$_config['memory']['yac'] = 1; //启动对 YAC的支持
$_config['memory']['apc'] = 0; // 启动对 APC 的支持
$_config['memory']['apcu'] = 0; // 启动对 APCu 的支持
$_config['memory']['xcache'] = 0; // 启动对 xcache 的支持
$_config['memory']['eaccelerator'] = 0; // 启动对 eaccelerator 的支持
$_config['memory']['wincache'] = 0; // 启动对 wincache 的支持
$_config['memory']['yac'] = 0; //启动对 YAC 的支持
$_config['memory']['file']['server'] = 'data/cache/filecache'; // 启动对 File 缓存的支持
// 服务器相关设置
$_config['server']['id'] = 1; // 服务器编号多webserver的时候用于标识当前服务器的ID

View File

@ -0,0 +1,102 @@
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: memory_driver_yac.php 27635 2017-02-02 17:02:46Z NaiXiaoxIN $
*/
if (!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class memory_driver_file {
public $cacheName = 'File';
public $enable;
public $path;
public function env() {
return true;
}
public function init($config) {
$this->path = $config['server'].'/';
if($config['server']) {
$this->enable = is_dir(DISCUZ_ROOT.$this->path);
if(!$this->enable) {
dmkdir(DISCUZ_ROOT.$this->path);
$this->enable = is_dir(DISCUZ_ROOT.$this->path);
}
} else {
$this->enable = false;
}
}
private function cachefile($key) {
return str_replace('_', '/', $key).'/'.$key;
}
public function get($key) {
$data = false;
@include_once DISCUZ_ROOT.$this->path.$this->cachefile($key).'.php';
if($data !== false) {
if($data['exp'] && $data['exp'] < TIMESTAMP) {
return false;
}
return $data['data'];
}
}
public function set($key, $value, $ttl = 0) {
$file = DISCUZ_ROOT.$this->path.$this->cachefile($key).'.php';
dmkdir(dirname($file));
$data = array(
'exp' => $ttl ? TIMESTAMP + $ttl : 0,
'data' => $value,
);
return file_put_contents($file, "<?php\n\$data = ".var_export($data, 1).";\n");
}
public function rm($key) {
return @unlink(DISCUZ_ROOT.$this->path.$this->cachefile($key));
}
private function dir_clear($dir) {
if($directory = @dir($dir)) {
while($entry = $directory->read()) {
$filename = $dir.'/'.$entry;
if($entry != '.' && $entry != '..') {
if(is_file($filename)) {
@unlink($filename);
} else {
$this->dir_clear($filename);
@rmdir($filename);
}
}
}
$directory->close();
}
}
public function clear() {
return $this->dir_clear(DISCUZ_ROOT.$this->path);
}
public function inc($key, $step = 1) {
$old = $this->get($key);
if (!$old) {
return false;
}
return $this->set($key, $old + $step);
}
public function dec($key, $step = 1) {
$old = $this->get($key);
if (!$old) {
return false;
}
return $this->set($key, $old - $step);
}
}