+ Add clean cache cron.
This commit is contained in:
@@ -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.';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user