1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79:
<?php
class CacheService
{
private static $all_files_regex_without_extensions = '`^\.|.*\.log|apc.php|debug.php`iu';
private static $cache_folder;
private static $tpl_cache_folder;
private static $css_cache_folder;
private static $syndication_cache_folder;
public function __construct()
{
self::$cache_folder = new Folder(PATH_TO_ROOT . '/cache');
self::$tpl_cache_folder = new Folder(self::$cache_folder->get_path() . '/tpl');
self::$css_cache_folder = new Folder(self::$cache_folder->get_path() . '/css');
self::$syndication_cache_folder = new Folder(self::$cache_folder->get_path() . '/syndication');
}
public function clear_cache()
{
$this->clear_phpboost_cache();
$this->clear_template_cache();
$this->clear_css_cache();
$this->clear_syndication_cache();
}
public function clear_phpboost_cache()
{
CacheManager::clear();
$this->delete_files(self::$cache_folder, self::$all_files_regex_without_extensions);
}
public function clear_template_cache()
{
$this->delete_files(self::$tpl_cache_folder, self::$all_files_regex_without_extensions, true);
}
public function clear_css_cache()
{
$this->delete_files(self::$css_cache_folder, self::$all_files_regex_without_extensions, true);
}
public function clear_syndication_cache()
{
$this->delete_files(self::$syndication_cache_folder, self::$all_files_regex_without_extensions);
}
private function delete_files(Folder $folder, $regex = '', $delete_sub_folders = false)
{
$files_to_delete = $folder->get_files($regex, true);
foreach ($files_to_delete as $file)
{
if ($file->exists())
$file->delete();
}
if ($delete_sub_folders)
{
foreach ($folder->get_folders() as $f)
{
$this->delete_files($f, self::$all_files_regex_without_extensions, true);
}
}
}
}
?>