From 1a2a48e1292a3730bb11e9fa063be6b7645ebc1e Mon Sep 17 00:00:00 2001 From: logmanoriginal Date: Sat, 10 Sep 2016 00:00:10 +0200 Subject: [PATCH] [HttpCachingBridgeAbstract] Use sha1 cache file names Previously folder hierarchies were created based on the input URL which could result in very deep folder structures. Using SHA1 file names also allows to check for old files more effectively (via fileatime) --- lib/HttpCachingBridgeAbstract.php | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/lib/HttpCachingBridgeAbstract.php b/lib/HttpCachingBridgeAbstract.php index d7edcd7d..66530640 100644 --- a/lib/HttpCachingBridgeAbstract.php +++ b/lib/HttpCachingBridgeAbstract.php @@ -25,7 +25,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract { if(file_exists($filepath)){ $this->debugMessage('loading cached file from ' . $filepath . ' for page at url ' . $url); // TODO touch file and its parent, and try to do neighbour deletion - $this->refresh_in_cache($filepath); + touch($filepath); $content = file_get_contents($filepath); } else { $this->debugMessage('we have no local copy of ' . $url . ' Downloading to ' . $filepath); @@ -55,34 +55,8 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract { return filectime($filepath); } - private function refresh_in_cache($filepath){ - $cacheDir = __DIR__ . '/../cache/pages/'; - $currentPath = $filepath; - while(!$cacheDir == $currentPath){ - touch($currentPath); - $currentPath = dirname($currentPath); - } - } - private function buildCacheFilePath($url){ - $cacheDir = __DIR__ . '/../cache/pages/'; - - $simplified_url = str_replace( - ['http://', 'https://', '?', '&', '='], - ['', '', '/', '/', '/'], - $url); - - if(substr($cacheDir, -1) !== '/'){ - $cacheDir .= '/'; - } - - $filepath = $cacheDir . $simplified_url; - - if(substr($filepath, -1) === '/'){ - $filepath .= 'index.html'; - } - - return realpath($filepath); + return __DIR__ . '/../cache/pages/' . sha1($url) . '.cache'; } public function remove_from_cache($url){