diff options
-rw-r--r-- | it_url.class | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/it_url.class b/it_url.class index ba194e7..26794be 100644 --- a/it_url.class +++ b/it_url.class @@ -703,25 +703,26 @@ static function get_cache($p = array()) it::log('debug', 'getcachelog', $p['id'], $p['url'], !$isnewfile ? "" : "fetched=" . mb_substr(is_string($data) ? $data : "(assoc)", 0, 400)); ### EDC('getcache', $success, $path); # too verbose - return $success ? ($p['returnheaders'] ? array($path, $headers) : $path) : false; + return !$success ? false : ($p['returnheaders'] ? [$path, $headers] : ($p['returncachemiss'] ? [$path, $isnewfile] : $path)); } /** * Fetch a file, cache it and return contents * @param @see it_url::get_cache() - * @param $p['assoc'] Return [ 'data' => string, 'status' => int, 'cookies' => array, 'headers' => array, 'errstr' => string ] instead of just data + * @param $p['assoc'] Return [ 'data' => string, 'status' => int, 'cookies' => array, 'headers' => array, 'errstr' => string, 'cachemiss' => bool ] instead of just data * @return @see it_url::get() */ static function get_cache_contents($p) { - if ($fn = self::get_cache($p)) + [$fn, $cachemiss] = self::get_cache($p + ['returncachemiss' => true]); + if ($fn) { $result = it::file_get_contents($fn); if ($p['assoc']) { $response = it::match('^\{', $result) ? it::json_decode($result, 'assoc' => true) : unserialize($result); # FIXME 2023-05 UM remove legacy support $response['data'] = self::_postprocess($response['data'], $p); - $result = $response; + $result = $response + ['cachemiss' => $cachemiss]; } else $result = self::_postprocess($result, $p); |