change file_* to use cache

This make all static files not written to disk but the memory instead thus reducing disk io
This commit is contained in:
root 2015-12-22 01:53:45 -05:00
parent 303ed52812
commit 499e609ec7

View File

@ -630,6 +630,16 @@ function purge($uri) {
function file_write($path, $data, $simple = false, $skip_purge = false) {
global $config, $debug;
//echo "file_write($path, ", strlen($data), ", $simple, $skip_purge)<br>\n";
Cache::store('vichan_filecache_'.$path, $data, -1);
if ($config['gzip_static']) {
$bytes=strlen($data);
if ($bytes & ~0x3ff) {
Cache::store('vichan_filecache_'.$path.'.gz', gzencode($data), -1);
} else {
Cache::delete('vichan_filecache_'.$path.'.gz');
}
}
if (preg_match('/^remote:\/\/(.+)\:(.+)$/', $path, $m)) {
if (isset($config['remote'][$m[1]])) {
@ -643,6 +653,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
}
}
/*
if (!$fp = fopen($path, $simple ? 'w' : 'c'))
error('Unable to open file for writing: ' . $path);
@ -666,7 +677,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
// Close
if (!fclose($fp))
error('Unable to close file: ' . $path);
*/
/**
* Create gzipped file.
*
@ -675,6 +686,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
*
* This is useful with nginx with gzip_static on.
*/
/*
if ($config['gzip_static']) {
$gzpath = "$path.gz";
@ -688,6 +700,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
@unlink($gzpath);
}
}
*/
if (!$skip_purge && isset($config['purge'])) {
// Purge cache
@ -705,6 +718,7 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
}
if ($config['debug']) {
$bytes=strlen($data);
$debug['write'][] = $path . ': ' . $bytes . ' bytes';
}
@ -713,6 +727,12 @@ function file_write($path, $data, $simple = false, $skip_purge = false) {
function file_unlink($path) {
global $config, $debug;
//echo "file_unlink($path)<br>\n";
if ($config['gzip_static']) {
Cache::delete('vichan_filecache_'.$path);
} else {
Cache::delete('vichan_filecache_'.$path.'.gz');
}
if ($config['debug']) {
if (!isset($debug['unlink']))
@ -720,14 +740,14 @@ function file_unlink($path) {
$debug['unlink'][] = $path;
}
$ret=true;
/*
$ret = @unlink($path);
if ($config['gzip_static']) {
$gzpath = "$path.gz";
@unlink($gzpath);
}
*/
if (isset($config['purge']) && $path[0] != '/' && isset($_SERVER['HTTP_HOST'])) {
// Purge cache
if (basename($path) == $config['file_index']) {