From aedd62e2b84b4ea0d3c03f5c23ec594f4ebb1c17 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 13 Aug 2015 21:39:51 +0200 Subject: Cache: simplify cached content cleanup, improve tests Signed-off-by: VirtualTam --- application/Cache.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'application') diff --git a/application/Cache.php b/application/Cache.php index 9c7e818f..5d050165 100644 --- a/application/Cache.php +++ b/application/Cache.php @@ -7,26 +7,18 @@ * Purges all cached pages * * @param string $pageCacheDir page cache directory + * + * @return mixed an error string if the directory is missing */ function purgeCachedPages($pageCacheDir) { if (! is_dir($pageCacheDir)) { - return; + $error = 'Cannot purge '.$pageCacheDir.': no directory'; + error_log($error); + return $error; } - // TODO: check write access to the cache directory - - $handler = opendir($pageCacheDir); - if ($handler == false) { - return; - } - - while (($filename = readdir($handler)) !== false) { - if (endsWith($filename, '.cache')) { - unlink($pageCacheDir.'/'.$filename); - } - } - closedir($handler); + array_map('unlink', glob($pageCacheDir.'/*.cache')); } /** -- cgit v1.2.3