+ Add clean cache cron.

This commit is contained in:
Lufei
2023-06-08 15:40:11 +08:00
parent d6bd6b97a7
commit 746dbdaa08
4 changed files with 54 additions and 1 deletions
+19
View File
@@ -338,4 +338,23 @@ class misc extends control
if(strpos(",$accounts,", $this->app->user->account) === false) $accounts .= ',' . $this->app->user->account;
$this->loadModel('setting')->setItem('system.common.global.skip' . ucfirst($feature), $accounts);
}
/**
* Clean cache files.
*
* @return void
*/
public function cleanCache()
{
$cacheConfig = $this->config->cache;
if(!$cacheConfig->enable && !$cacheConfig->enableFullPage)
{
echo 'Cache is disabled.';
return;
}
$this->misc->getCacheFiles(rtrim($this->app->getCacheRoot(), DS));
echo 'Cleaned cache files.';
}
}
+32
View File
@@ -134,4 +134,36 @@ class miscModel extends model
return $weakSites;
}
/**
* Get cache files.
*
* @param string $directory
* @return void
*/
public function getCacheFiles($directory)
{
$files = glob($directory . DS . '*.cache');
foreach($files as $file) $this->readCacheFile($file);
$subdirectories = glob($directory . DS . '*', GLOB_ONLYDIR);
foreach($subdirectories as $subdirectory) $this->getCacheFiles($subdirectory);
}
/**
* Read cache file content, and delete it if expired.
*
* @param string $file
* @return bool
*/
public function readCacheFile($file)
{
$content = file_get_contents($file);
$content = unserialize($content);
if(is_null($content['time'])) return false;
if(time() > $content['time']) return unlink($file);
}
}