Improved caching behaviour and allowed subclasses to easily use logging 'infrastructure'
This commit is contained in:
parent
fda3e9886e
commit
954bc4dde0
1 changed files with 12 additions and 2 deletions
|
@ -90,7 +90,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
* @return content of file as string
|
* @return content of file as string
|
||||||
*/
|
*/
|
||||||
public function get_cached($url) {
|
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
|
// TODO build this from the variable given to Cache
|
||||||
$pageCacheDir = __DIR__ . '/../cache/'."pages/";
|
$pageCacheDir = __DIR__ . '/../cache/'."pages/";
|
||||||
$filename = $pageCacheDir.$simplified_url;
|
$filename = $pageCacheDir.$simplified_url;
|
||||||
|
@ -98,6 +98,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
$filename = $filename."index.html";
|
$filename = $filename."index.html";
|
||||||
}
|
}
|
||||||
if(file_exists($filename)) {
|
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
|
// TODO touch file and its parent, and try to do neighbour deletion
|
||||||
$currentPath = $filename;
|
$currentPath = $filename;
|
||||||
while(!$pageCacheDir==$currentPath) {
|
while(!$pageCacheDir==$currentPath) {
|
||||||
|
@ -105,7 +106,7 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
$currentPath = dirname($currentPath);
|
$currentPath = dirname($currentPath);
|
||||||
}
|
}
|
||||||
} else {
|
} 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, '/'));
|
$dir = substr($filename, 0, strrpos($filename, '/'));
|
||||||
if(!is_dir($dir)) {
|
if(!is_dir($dir)) {
|
||||||
mkdir($dir, 0777, true);
|
mkdir($dir, 0777, true);
|
||||||
|
@ -125,6 +126,15 @@ abstract class HttpCachingBridgeAbstract extends BridgeAbstract {
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
fclose($f);
|
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{
|
class Bridge{
|
||||||
|
|
Loading…
Reference in a new issue