* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key * @param {import('../../types/cache-interceptor.d.ts').default.CacheValue & { body: null | Buffer | Array }} value
(key, value)
| 258 | * @param {import('../../types/cache-interceptor.d.ts').default.CacheValue & { body: null | Buffer | Array<Buffer>}} value |
| 259 | */ |
| 260 | set (key, value) { |
| 261 | assertCacheKey(key) |
| 262 | |
| 263 | const url = this.#makeValueUrl(key) |
| 264 | const body = Array.isArray(value.body) ? Buffer.concat(value.body) : value.body |
| 265 | const size = body?.byteLength |
| 266 | |
| 267 | if (size && size > this.#maxEntrySize) { |
| 268 | return |
| 269 | } |
| 270 | |
| 271 | const existingValue = this.#findValue(key, true) |
| 272 | if (existingValue) { |
| 273 | // Updating an existing response, let's overwrite it |
| 274 | this.#updateValueQuery.run( |
| 275 | body, |
| 276 | value.deleteAt, |
| 277 | value.statusCode, |
| 278 | value.statusMessage, |
| 279 | value.headers ? JSON.stringify(value.headers) : null, |
| 280 | value.etag ? value.etag : null, |
| 281 | value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null, |
| 282 | value.vary ? JSON.stringify(value.vary) : null, |
| 283 | value.cachedAt, |
| 284 | value.staleAt, |
| 285 | existingValue.id |
| 286 | ) |
| 287 | } else { |
| 288 | // New response, let's insert it |
| 289 | this.#insertValueQuery.run( |
| 290 | url, |
| 291 | key.method, |
| 292 | body, |
| 293 | value.deleteAt, |
| 294 | value.statusCode, |
| 295 | value.statusMessage, |
| 296 | value.headers ? JSON.stringify(value.headers) : null, |
| 297 | value.etag ? value.etag : null, |
| 298 | value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null, |
| 299 | value.vary ? JSON.stringify(value.vary) : null, |
| 300 | value.cachedAt, |
| 301 | value.staleAt |
| 302 | ) |
| 303 | this.#prune() |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key |
no test coverage detected