From f71e0793f686dee0ff7acfed45e58cef4849b3e4 Mon Sep 17 00:00:00 2001 From: Urban Müller Date: Wed, 26 Oct 2022 15:21:02 +0200 Subject: more readable code, better docs, bigger default cleanup time window --- it_url.class | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'it_url.class') 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); -- cgit v1.2.3