From 01e48f269df59e02798dad4a698c125d76b0ed70 Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Thu, 9 Jul 2015 22:14:39 +0200 Subject: CachedPage: move to a proper file, add tests Modifications - rename `pageCache` to `CachedPage` - move utilities to `Cache` - do not access globals - apply coding rules - update LinkDB and test code - add test coverage Signed-off-by: VirtualTam --- application/Cache.php | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 application/Cache.php (limited to 'application/Cache.php') diff --git a/application/Cache.php b/application/Cache.php new file mode 100644 index 00000000..9c7e818f --- /dev/null +++ b/application/Cache.php @@ -0,0 +1,46 @@ + 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/Cache.php') 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