diff --git a/api/v1/database/mastodon/accounts/search/index.php b/api/v1/database/mastodon/accounts/search/index.php index 351ae31..3d5d35b 100644 --- a/api/v1/database/mastodon/accounts/search/index.php +++ b/api/v1/database/mastodon/accounts/search/index.php @@ -1,3 +1,4 @@ + diff --git a/base.php b/base.php index f7ee360..731c85e 100644 --- a/base.php +++ b/base.php @@ -56,6 +56,10 @@ function apiresult($data, $code=200) { if ($code !== 200) http_response_code($code); header('Content-Type: application/json'); } + + if (isset($GLOBALS['http_cache_config'])) + content_cache__put($GLOBALS['http_cache_config']['key'], + 'ondemand,'.$GLOBALS['http_cache_config']['seconds'], $data); if (gettype($data) !== 'string') echo json_encode($data); else echo $data; @@ -611,6 +615,19 @@ function matches_comparing_expression($expr, $text, $debug=false) { return in_array($result, [0,false]) ? false : true; } +function http_cache($seconds, $data=null) { + if ($data === null) + $data = $_GET; + $cache_key = sha1('http_cache'.json_encode($data)); + $cache = content_cache__get($cache_key); + if ($cache !== null) + return apiresult($cache); + $GLOBALS['http_cache_config'] = [ + 'seconds' => $seconds, + 'key' => $cache_key + ]; +} + function _cachekey_construct(...$keys) { $nkeys = []; foreach ($keys as $key)