. * */ namespace Vvveb\Controller\Tools; use function Vvveb\__; use Vvveb\Controller\Base; use Vvveb\System\CacheManager; class Cache extends Base { private function clear($fn) { if ($fn()) { $this->view->success[] = __('Cache deleted!'); } else { $this->view->errors[] = __('Error purging cache!'); } return $this->index(); } function delete() { return $this->clear(function () { return CacheManager :: delete(); }); } function template() { return $this->clear(function () { return CacheManager :: clearCompiledFiles(); }); } function page() { return $this->clear(function () { return CacheManager :: clearPageCache($this->global['site_url']); }); } function database() { return $this->clear(function () { return CacheManager :: clearObjectCache(); }); } function asset() { return $this->clear(function () { return CacheManager :: clearFrontend(); }); } function model() { return $this->clear(function () { return CacheManager :: clearModelCache(); }); } function image() { return $this->clear(function () { return CacheManager :: clearImageCache(); }); } function stale() { return $this->index(); } function index() { $folders = [ '/public/page-cache' => DIR_PUBLIC . PAGE_CACHE_DIR, '/public/image-cache' => DIR_PUBLIC . DS . 'image-cache', '/storage/model/app' => DIR_STORAGE . 'model' . DS . 'app', '/storage/model/admin' => DIR_STORAGE . 'model' . DS . 'admin', '/storage/compiled_templates' => DIR_COMPILED_TEMPLATES, ]; $unwritable = []; foreach ($folders as $folder => $path) { if (! is_writable($path)) { $unwritable[] = $folder; } } if ($unwritable) { $this->view->info[] = sprintf('Folders %s are not writable, clear cache might not work for these layers', implode(', ', $unwritable)); } } }