mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-06 08:37:30 +02:00
Destroyed HttpCachingBridgeAbstract (markdown)
@@ -1,45 +0,0 @@
|
||||
`HttpCachingBridgeAbstract` extends [`BridgeAbstract`](BridgeAbstract) and adds functions to store contents into a local cache in order to reduce bandwidth requirements.
|
||||
|
||||
**Usage example**: _Your bridge loads one page and collects a range of items. Optionally the full article can be included for each item. It is not recommended to always download ALL full articles. Instead full articles of already requested items can be stored in the local cache, so the next time the same request is processed, the full articles are loaded from cache rather than re-downloading them from the internet again._
|
||||
|
||||
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)
|
||||
|
||||
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. 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', 86400);
|
||||
```
|
||||
|
||||
or if you require the HTML DOM:
|
||||
|
||||
```PHP
|
||||
$html = str_get_html($this->get_cached('your URL', 86400));
|
||||
```
|
||||
|
||||
# Template
|
||||
|
||||
This is the template for a new bridge:
|
||||
|
||||
```PHP
|
||||
<?php
|
||||
class MySiteBridge extends HttpCachingBridgeAbstract {
|
||||
const MAINTAINER = 'No maintainer';
|
||||
const NAME = 'Unnamed bridge';
|
||||
const URI = '';
|
||||
const DESCRIPTION = 'No description provided';
|
||||
const PARAMETERS = array();
|
||||
|
||||
public function collectData(){
|
||||
// Implement your bridge here!
|
||||
|
||||
$html = str_get_html($this->get_cached('your URL', 43200)); // 12h duration
|
||||
}
|
||||
}
|
||||
// Imaginary empty line!
|
||||
```
|
Reference in New Issue
Block a user