diff options
Diffstat (limited to 'it_url.class')
-rw-r--r-- | it_url.class | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/it_url.class b/it_url.class index a2cbb5e..a0671fb 100644 --- a/it_url.class +++ b/it_url.class @@ -574,6 +574,7 @@ static function get_cache_filename($p) * @param $p['cachedir'] directory to store cache files in, @see get_cache_dir * @param $p['timeout'] timeout in seconds, default 10. fractions allowed * @param $p['maxage'] maximum age of cache entries in seconds, default 23 hours. id mandatory if given + * @param $p['randomexpire'] chance to randomly expunge an entry, 0..1 * @param $p['cleanbefore'] maximum seconds since midnight when initiating expire, default 10800 * @param $p['preprocess'] callback function (or array for methods) to change received file or array('function' => ..., 'in' => $src, 'out' => $dst, ...) with callback function plus args * @param $p['safety'] DEPRECATED. see $p['it_error'] @@ -600,7 +601,7 @@ static function get_cache($p = array()) if (!is_writable(dirname($path))) it::error("parent dir not writable: " . trim(it::exec('ls -ld {dir} 2>&1', ['dir' => dirname($path)]))); - if (($filemtime = it_url::_expired($path, $p['maxage'])) || ($p['returnheaders'] && !file_exists(("$path.headers")))) # Outdated(non-zero int) or non-existant(true)? + if (($filemtime = it_url::_expired($path, $p['maxage'], $p['randomexpire'])) || ($p['returnheaders'] && !file_exists(("$path.headers")))) # Outdated(non-zero int) or non-existant(true)? { $fileexists = $filemtime !== true; @@ -737,11 +738,11 @@ static function get_cache_contents($p) * @param $maxage Maximum age of file in seconds * @return Not expired: false | Non-existant file: true | Timestamp of expired file */ -static function _expired($path, $maxage) +static function _expired($path, $maxage, $randomexpire = 0) { if ($result = EDC('nocache') ? false : @filemtime($path)) { - if (time() - $result > $maxage) + if (time() - $result > $maxage || mt_rand(0, 100000) < $randomexpire * 100000) EDC('getcache', "expired", $maxage, $path); else $result = false; |