[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
This commit is contained in:
logmanoriginal 2018-03-09 19:37:34 +01:00
parent 72691eee67
commit 877b123838

View File

@ -19,6 +19,10 @@ define('PROXY_BYBRIDGE', false);
// Comment this line or keep PROXY_NAME empty to display PROXY_URL instead // Comment this line or keep PROXY_NAME empty to display PROXY_URL instead
define('PROXY_NAME', 'Hidden Proxy Name'); define('PROXY_NAME', 'Hidden Proxy Name');
// Allows the operator to specify custom cache timeouts via '&_cache_timeout=3600'
// true: enabled (default), false: disabled
define('CUSTOM_CACHE_TIMEOUT', true);
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
error_reporting(0); error_reporting(0);
@ -168,6 +172,16 @@ try {
define('NOPROXY', true); define('NOPROXY', true);
} }
// Custom cache timeout
$cache_timeout = -1;
if(array_key_exists('_cache_timeout', $params)) {
if(!CUSTOM_CACHE_TIMEOUT) {
throw new \HttpException('This server doesn\'t support "_cache_timeout"!');
}
$cache_timeout = filter_var($params['_cache_timeout'], FILTER_VALIDATE_INT);
}
// Initialize cache // Initialize cache
$cache = Cache::create('FileCache'); $cache = Cache::create('FileCache');
$cache->setPath(CACHE_DIR); $cache->setPath(CACHE_DIR);
@ -178,10 +192,12 @@ try {
unset($params['bridge']); unset($params['bridge']);
unset($params['format']); unset($params['format']);
unset($params['_noproxy']); unset($params['_noproxy']);
unset($params['_cache_timeout']);
// Load cache & data // Load cache & data
try { try {
$bridge->setCache($cache); $bridge->setCache($cache);
$bridge->setCacheTimeout($cache_timeout);
$bridge->setDatas($params); $bridge->setDatas($params);
} catch(Exception $e) { } catch(Exception $e) {
http_response_code($e->getCode()); http_response_code($e->getCode());