* GET request. * @param {string} path * @param {boolean} [bypassCache=false] - when true, skips the cache read and * writes the fresh result back into it. * @returns {Promise }
(path, bypassCache = false)
| 175 | * @returns {Promise<APIResult>} |
| 176 | */ |
| 177 | async function get(path, bypassCache = false) { |
| 178 | if (!bypassCache) { |
| 179 | const cached = _cacheGet(path); |
| 180 | if (cached && Date.now() < cached.expires) { |
| 181 | console.log('Loaded from cache:', path); |
| 182 | return cached.result; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | const result = await request('GET', path); |
| 187 | if (result.ok) { |
| 188 | console.log('Loaded new:', path); |
| 189 | _cacheSet(path, { result, expires: Date.now() + CACHE_TTL_MS }); |
| 190 | } |
| 191 | return result; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * POST request. |