mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-05 16:17:28 +02:00
Implement customizable cache timeout (#641)
* [BridgeAbstract] Implement customizable cache timeout The customizable cache timeout is used instead of the default cache timeout (CACHE_TIMEOUT) if specified by the caller. * [index] Add new global parameter '_cache_timeout' The _cache_timeout parameter is an optional parameter that can be used to specify a custom cache timeout. This option is enabled by default. It can be disabled using the named constant 'CUSTOM_CACHE_TIMEOUT' which supports two states: > true: Enabled (default) > false: Disabled * [BridgeAbstract] Change scope of 'getCacheTimeout' to public * [html] Add cache timeout parameter to all bridges The timeout parameter only shows if CUSTOM_CACHE_TIMEOUT has been set to true. The default value is automatically set to the value specified in the bridge. * [index] Disable custom cache timeout by default
This commit is contained in:
@@ -14,6 +14,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||
protected $items = array();
|
||||
protected $inputs = array();
|
||||
protected $queriedContext = '';
|
||||
protected $cacheTimeout;
|
||||
|
||||
/**
|
||||
* Return cachable datas (extrainfos and items) stored in the bridge
|
||||
@@ -171,7 +172,7 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||
if(!is_null($this->cache)) {
|
||||
$time = $this->cache->getTime();
|
||||
if($time !== false
|
||||
&& (time() - static::CACHE_TIMEOUT < $time)
|
||||
&& (time() - $this->getCacheTimeout() < $time)
|
||||
&& (!defined('DEBUG') || DEBUG !== true)) {
|
||||
$cached = $this->cache->loadData();
|
||||
if(isset($cached['items']) && isset($cached['extraInfos'])) {
|
||||
@@ -268,4 +269,17 @@ abstract class BridgeAbstract implements BridgeInterface {
|
||||
public function setCache(\CacheInterface $cache){
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
public function setCacheTimeout($timeout){
|
||||
if(is_numeric($timeout) && ($timeout < 1 || $timeout > 86400)) {
|
||||
$this->cacheTimeout = static::CACHE_TIMEOUT;
|
||||
return;
|
||||
}
|
||||
|
||||
$this->cacheTimeout = $timeout;
|
||||
}
|
||||
|
||||
public function getCacheTimeout(){
|
||||
return isset($this->cacheTimeout) ? $this->cacheTimeout : static::CACHE_TIMEOUT;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user