summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2022-10-26 15:21:02 +0200
committerUrban Müller2022-10-26 15:21:02 +0200
commitf71e0793f686dee0ff7acfed45e58cef4849b3e4 (patch)
treec433fef546e63b143f0b3b65fdc179f70568730c
parent4e0d1fdd60ec8a2384f1ad7dac5c6b5b0099a031 (diff)
downloaditools-f71e0793f686dee0ff7acfed45e58cef4849b3e4.tar.gz
itools-f71e0793f686dee0ff7acfed45e58cef4849b3e4.tar.bz2
itools-f71e0793f686dee0ff7acfed45e58cef4849b3e4.zip
more readable code, better docs, bigger default cleanup time window
-rw-r--r--it_url.class9
1 files changed, 5 insertions, 4 deletions
diff --git a/it_url.class b/it_url.class
index b0aeb9f..b41a1f3 100644
--- a/it_url.class
+++ b/it_url.class
@@ -572,7 +572,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['cleanbefore'] maximum daytime when attempting cleanup, default 7200
+ * @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']
* @param $p['it_error'] parameters for it::error(), false means ignore errors, anything else gets passed to it::error() if errors occur
@@ -587,7 +587,7 @@ static function get_cache($p = array())
if (!$p['id'] && $p['maxage'])
it::error("calling get_cache with maxage and without id");
- $p += ['timeout' => 10, 'maxage' => 23 * 3600, 'cleanbefore' => 7200, 'lock' => true, 'it_error' => $p['safety'] === 0 ? false : ($p['safety'] == 2 ? ['fatal' => true] : [])];
+ $p += ['timeout' => 10, 'maxage' => 23 * 3600, 'cleanbefore' => 10800, 'lock' => true, 'it_error' => $p['safety'] === 0 ? false : ($p['safety'] == 2 ? ['fatal' => true] : [])];
$p['totaltimeout'] = $p['timeout'];
$path = it_url::get_cache_filename($p); # Must be before changing cachedir below
$p['cachedir'] = it_url::get_cache_dir($p);
@@ -687,8 +687,9 @@ static function get_cache($p = array())
}
}
- # cache cleanup preferably at night
- if (time() - @filemtime($p['cachedir'] . "/cleaned") > ((date('H') >= 1 && date('H')*3600 + date('i')*60 < $p['cleanbefore']) ? 80000 : 2*80000))
+ # cache cleanup, preferably at night
+ $isnight = date('H') >= 1 && date('H')*3600 + date('i')*60 < $p['cleanbefore'];
+ if (time() - @filemtime($p['cachedir'] . "/cleaned") > ($isnight ? 80000 : 2*80000))
{
it::file_put($p['cachedir'] . "/cleaned", ""); # touch could have permission problems
$maxagemin = intval($p['maxage']/60);