From 656f52d988e222417e8b38e55ddc62b5218cc7b4 Mon Sep 17 00:00:00 2001 From: LogMANOriginal Date: Fri, 9 Sep 2016 22:41:51 +0200 Subject: [PATCH] [HttpCachingBridgeAbstract] Update to latest version --- HttpCachingBridgeAbstract.md | 38 ++++-------------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/HttpCachingBridgeAbstract.md b/HttpCachingBridgeAbstract.md index 528c8b1..59f8ade 100644 --- a/HttpCachingBridgeAbstract.md +++ b/HttpCachingBridgeAbstract.md @@ -5,43 +5,21 @@ To create a new Bridge extending `HttpCachingBridgeAbstract` you must implement all required functions of [`BridgeAbstract`](BridgeAbstract). `HttpCachingBridgeAbstract` additionally provides following functions: * [`get_cached`](#the-get_cached-function) -* [`get_cached_time`](#the-get_cached_time-function) -* [`remove_from_cache`](#the-remove_from_cache-function) Find a [template](#template) at the end of this file. ## The `get_cached` function -This function receives the contents of a given URL from cache or, in case the contents have not yet been cached, from the internet. +This function receives the contents of a given URL from cache or, in case the contents have not yet been cached, from the internet. You can optionally pass the cache duration as second parameter. If no cache duration is specified, the default value of 24h (86400 seconds) applies. ```PHP -$this->get_cached('your URL'); +$this->get_cached('your URL', 86400); ``` or if you require the HTML DOM: ```PHP -$html = str_get_html($this->get_cached('your URL'); -``` - -## The `get_cached_time` function - -This function returns the time stamp of the cached file for a given URL. - -```PHP -$timestamp = $this->get_cached_time('your URL'); -``` - -**Notice:** This function will download the contents, if the cache file for the given URL does not yet exist! - -## The `remove_from_cache` function - -**Important notice:** This function is not yet fully implemented (file is not actually removed from cache)! - -This function removes the cached file for a given URL from the cache. - -```PHP -$this->remove_from_cache('your URL'); +$html = str_get_html($this->get_cached('your URL', 86400)); ``` # Template @@ -60,15 +38,7 @@ class MySiteBridge extends HttpCachingBridgeAbstract { public function collectData(){ // Implement your bridge here! - // Example for caching a page with automatic removal after 12 hours - $url = ''; // Insert your URL here! - $timestamp = $this->get_cached_time($url); - - if($timestamp <= strtotime('-12 hours')){ // Cached file is too old (might have changed) - $this->remove_from_cache($url); - } - - $html = str_get_html($this->get_cached($url)); + $html = str_get_html($this->get_cached('your URL', 43200)); // 12h duration } } // Imaginary empty line!