Remove "always" cache-creating files when it's related cache has not been accesed 7 days

This commit is contained in:
Bofh 2022-12-21 01:20:33 +01:00
parent 45b3e5cb15
commit f09df04fd3
1 changed files with 16 additions and 2 deletions

View File

@ -109,13 +109,27 @@ function run__cronjobs_cache_cleanup() {
unlink($cache_dir.'/'.$fl);
}
}
$dir = $GLOBALS['appconf']['data_dir'].'/cron/db';
$crondb_dir = $GLOBALS['appconf']['data_dir'].'/cron/db';
foreach (scandir($crondb_dir) as $fl) {
if (in_array($fl, ['.','..']))
continue;
$cron_file = $crondb_dir.'/'.$fl;
$data = @unserialize(file_get_contents($cron_file));
if ($data === false || !isset($data['last_accessed']))
continue;
$ms = time() - $data['last_accessed'];
$days_diff = intval($ms / 60 / 60 / 24);
if ($days_diff >= 7) {
logi('CACHE-CLEANUP remove cron/db cache creator file: '.$fl);
unlink($cron_file);
}
}
foreach ($others as $fl) {
$ps = explode(',',$fl);
if (count($ps) === 2 && $ps[1] === 'always') {
$id = $ps[0];
$contains = false;
foreach (scandir($dir) as $f) {
foreach (scandir($crondb_dir) as $f) {
if (in_array($f, ['.','..']))
continue;
if (strpos($f, ','.$id.',') !== false) {