Remove "always"-tagged cache when unused

This commit is contained in:
Bofh 2022-12-21 00:26:47 +01:00
parent 5795a7fc0d
commit 3729dd5539
1 changed files with 24 additions and 1 deletions

View File

@ -88,12 +88,15 @@ function run__cronjobs_cache_cleanup() {
$cache_dir = $GLOBALS['appconf']['data_dir'].'/cache'; $cache_dir = $GLOBALS['appconf']['data_dir'].'/cache';
if (!file_exists($cache_dir)) if (!file_exists($cache_dir))
return; return;
$others = [];
foreach (scandir($cache_dir) as $fl) { foreach (scandir($cache_dir) as $fl) {
if (in_array($fl, ['.','..'])) if (in_array($fl, ['.','..']))
continue; continue;
$ps = explode(',',$fl); $ps = explode(',',$fl);
if ($ps[1] !== 'ondemand') if ($ps[1] !== 'ondemand') {
$others []= $fl;
continue; continue;
}
$time = intval($ps[2]); $time = intval($ps[2]);
$mtime = filemtime($cache_dir.'/'.$fl); $mtime = filemtime($cache_dir.'/'.$fl);
if (time() - $mtime >= $time) { if (time() - $mtime >= $time) {
@ -101,6 +104,26 @@ function run__cronjobs_cache_cleanup() {
unlink($cache_dir.'/'.$fl); unlink($cache_dir.'/'.$fl);
} }
} }
$dir = $GLOBALS['appconf']['data_dir'].'/cron/db';
foreach ($others as $fl) {
$ps = explode(',',$fl);
if (count($ps) === 2 && $ps[1] === 'always') {
$id = $ps[0];
$contains = false;
foreach (scandir($dir) as $f) {
if (in_array($f, ['.','..']))
continue;
if (strpos($f, ','.$id.',') !== false) {
$contains = true;
break;
}
}
if (!$contains) {
logi('CACHE-CLEANUP remove unused "always" cache: '.$fl);
unlink($cache_dir.'/'.$fl);
}
}
}
} }
run__cronjobs_cache_cleanup(); run__cronjobs_cache_cleanup();
// //