mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-04-23 15:06:53 +00:00
[BridgeAbstract] Implement customizable cache timeout
The customizable cache timeout is used instead of the default cache timeout (CACHE_TIMEOUT) if specified by the caller.
This commit is contained in:
parent
29a1c7ac09
commit
72691eee67
@ -14,6 +14,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||||||
protected $items = array();
|
protected $items = array();
|
||||||
protected $inputs = array();
|
protected $inputs = array();
|
||||||
protected $queriedContext = '';
|
protected $queriedContext = '';
|
||||||
|
protected $cacheTimeout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return cachable datas (extrainfos and items) stored in the bridge
|
* Return cachable datas (extrainfos and items) stored in the bridge
|
||||||
@ -171,7 +172,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||||||
if(!is_null($this->cache)) {
|
if(!is_null($this->cache)) {
|
||||||
$time = $this->cache->getTime();
|
$time = $this->cache->getTime();
|
||||||
if($time !== false
|
if($time !== false
|
||||||
&& (time() - static::CACHE_TIMEOUT < $time)
|
&& (time() - $this->getCacheTimeout() < $time)
|
||||||
&& (!defined('DEBUG') || DEBUG !== true)) {
|
&& (!defined('DEBUG') || DEBUG !== true)) {
|
||||||
$cached = $this->cache->loadData();
|
$cached = $this->cache->loadData();
|
||||||
if(isset($cached['items']) && isset($cached['extraInfos'])) {
|
if(isset($cached['items']) && isset($cached['extraInfos'])) {
|
||||||
@ -268,4 +269,28 @@ abstract class BridgeAbstract implements BridgeInterface {
|
|||||||
public function setCache(\CacheInterface $cache){
|
public function setCache(\CacheInterface $cache){
|
||||||
$this->cache = $cache;
|
$this->cache = $cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the cache timeout to the provided timeout value. The specified
|
||||||
|
* timeout must be between 1..86400, otherwise the default timeout is used.
|
||||||
|
*
|
||||||
|
* @param int $timeout The timeout in seconds
|
||||||
|
*/
|
||||||
|
public function setCacheTimeout($timeout){
|
||||||
|
if(is_numeric($timeout) && ($timeout < 1 || $timeout > 86400)) {
|
||||||
|
$this->cacheTimeout = static::CACHE_TIMEOUT;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->cacheTimeout = $timeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the cache timeout
|
||||||
|
*
|
||||||
|
* @return int Returns the cache timeout
|
||||||
|
*/
|
||||||
|
protected function getCacheTimeout(){
|
||||||
|
return isset($this->cacheTimeout) ? $this->cacheTimeout : static::CACHE_TIMEOUT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,13 @@ interface BridgeInterface {
|
|||||||
* @param object CacheInterface The cache instance
|
* @param object CacheInterface The cache instance
|
||||||
*/
|
*/
|
||||||
public function setCache(\CacheInterface $cache);
|
public function setCache(\CacheInterface $cache);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the timeout for clearing the cache files. The timeout must be
|
||||||
|
* specified between 1..86400 seconds (max. 24 hours). The default timeout
|
||||||
|
* (specified by the bridge maintainer) applies for invalid values.
|
||||||
|
*
|
||||||
|
* @param int $timeout The cache timeout in seconds
|
||||||
|
*/
|
||||||
|
public function setCacheTimeout($timeout);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user