mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-16 20:05:14 +02:00
New cache system with subdirectories
This commit is contained in:
parent
e67062d9cf
commit
f17377e6de
7 changed files with 83 additions and 86 deletions
51
boot.php
51
boot.php
|
@ -1847,3 +1847,54 @@ function random_digits($digits) {
|
|||
}
|
||||
return $rn;
|
||||
}
|
||||
|
||||
function get_cachefile($file, $writemode = true) {
|
||||
$cache = get_config("system","itemcache");
|
||||
|
||||
if ($cache == "")
|
||||
return("");
|
||||
|
||||
if (!is_dir($cache))
|
||||
return("");
|
||||
|
||||
$subfolder = $cache."/".substr($file, 0, 2);
|
||||
|
||||
$cachepath = $subfolder."/".$file;
|
||||
|
||||
if ($writemode) {
|
||||
if (!is_dir($subfolder)) {
|
||||
mkdir($subfolder);
|
||||
chmod($subfolder, 0777);
|
||||
}
|
||||
}
|
||||
|
||||
return($cachepath);
|
||||
}
|
||||
|
||||
function clear_cache($basepath = "", $path = "") {
|
||||
if ($path == "") {
|
||||
$basepath = get_config('system','itemcache');
|
||||
$path = $basepath;
|
||||
}
|
||||
|
||||
if (($path == "") OR (!is_dir($path)))
|
||||
return;
|
||||
|
||||
if (substr(realpath($path), 0, strlen($basepath)) != $basepath)
|
||||
return;
|
||||
|
||||
$cachetime = (int)get_config('system','itemcache_duration');
|
||||
if ($cachetime == 0)
|
||||
$cachetime = 86400;
|
||||
|
||||
if ($dh = opendir($path)) {
|
||||
while (($file = readdir($dh)) !== false) {
|
||||
$fullpath = $path."/".$file;
|
||||
if ((filetype($fullpath) == "dir") and ($file != ".") and ($file != ".."))
|
||||
clear_cache($basepath, $fullpath);
|
||||
if ((filetype($fullpath) == "file") and filectime($fullpath) < (time() - $cachetime))
|
||||
unlink($fullpath);
|
||||
}
|
||||
closedir($dh);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue