summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2023-03-23 17:36:13 +0100
committerUrban Müller2023-03-23 17:36:13 +0100
commitabf0ec9a4a770328bfb39916272d9d80654b1b75 (patch)
tree70a4581048ad9ba8cce8d422d6058a0a82b9d275
parent181342b8e9fd9106d3b1ab1fd0b808e299871766 (diff)
downloaditools-abf0ec9a4a770328bfb39916272d9d80654b1b75.tar.gz
itools-abf0ec9a4a770328bfb39916272d9d80654b1b75.tar.bz2
itools-abf0ec9a4a770328bfb39916272d9d80654b1b75.zip
support cachemiss flag
-rw-r--r--it_url.class9
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);