* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key * @param {boolean} [canBeExpired=false] * @returns {SqliteStoreValue | undefined}
(key, canBeExpired = false)
| 396 | * @returns {SqliteStoreValue | undefined} |
| 397 | */ |
| 398 | #findValue (key, canBeExpired = false) { |
| 399 | const url = this.#makeValueUrl(key) |
| 400 | const { headers, method } = key |
| 401 | |
| 402 | /** |
| 403 | * @type {SqliteStoreValue[]} |
| 404 | */ |
| 405 | const values = this.#getValuesQuery.all(url, method) |
| 406 | |
| 407 | if (values.length === 0) { |
| 408 | return undefined |
| 409 | } |
| 410 | |
| 411 | const now = Date.now() |
| 412 | for (const value of values) { |
| 413 | if (now >= value.deleteAt && !canBeExpired) { |
| 414 | continue |
| 415 | } |
| 416 | |
| 417 | let matches = true |
| 418 | |
| 419 | if (value.vary) { |
| 420 | const vary = JSON.parse(value.vary) |
| 421 | |
| 422 | for (const header in vary) { |
| 423 | if (!headerValueEquals(headers[header], vary[header])) { |
| 424 | matches = false |
| 425 | break |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (matches) { |
| 431 | return value |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | return undefined |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /** |
no test coverage detected