From 954bc4dde0f351eaf54f2833aa0aee9ede2ed48b Mon Sep 17 00:00:00 2001 From: Nicolas Delsaux Date: Wed, 26 Mar 2014 11:20:24 +0100 Subject: [PATCH] Improved caching behaviour and allowed subclasses to easily use logging 'infrastructure' --- lib/Bridge.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Bridge.php b/lib/Bridge.php index 3ef4a21..75f470e 100644 --- a/lib/Bridge.php +++ b/lib/Bridge.php @@ -90,7 +90,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract { * @return content of file as string */ public function get_cached($url) { - $simplified_url = str_replace(["http://", "https://", "?", "&"], ["", "", "/", "/"], $url); + $simplified_url = str_replace(["http://", "https://", "?", "&", "="], ["", "", "/", "/", "/"], $url); // TODO build this from the variable given to Cache $pageCacheDir = __DIR__ . '/../cache/'."pages/"; $filename = $pageCacheDir.$simplified_url; @@ -98,6 +98,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract { $filename = $filename."index.html"; } if(file_exists($filename)) { + // $this->message("loading cached file from ".$filename." for page at url ".$url); // TODO touch file and its parent, and try to do neighbour deletion $currentPath = $filename; while(!$pageCacheDir==$currentPath) { @@ -105,7 +106,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract { $currentPath = dirname($currentPath); } } else { - error_log("we have no local copy of ".$url." Downloading !"); + // $this->message("we have no local copy of ".$url." Downloading !"); $dir = substr($filename, 0, strrpos($filename, '/')); if(!is_dir($dir)) { mkdir($dir, 0777, true); @@ -125,6 +126,15 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract { fclose($handle); fclose($f); } + + public function message($text) { + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); + $calling = $backtrace[2]; + $message = $calling["file"].":".$calling["line"] + ." class ".get_class($this)."->".$calling["function"] + ." - ".$text; + error_log($message); + } } class Bridge{