Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: SqliteStoreValue #4015

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions lib/cache/sqlite-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@ const MAX_ENTRY_SIZE = 2 * 1000 * 1000 * 1000
*
* @typedef {{
* id: Readonly<number>
* headers?: Record<string, string | string[]>
* vary?: string | object
* body: string
* } & import('../../types/cache-interceptor.d.ts').default.CacheValue} SqliteStoreValue
* body?: Buffer
* statusCode: number
* statusMessage: string
* headers?: string
* vary?: string
* etag?: string
* cacheControlDirectives?: string
* cachedAt: number
* staleAt: number
* deleteAt: number
* }} SqliteStoreValue
*/

module.exports = class SqliteCacheStore {
#maxEntrySize = MAX_ENTRY_SIZE
#maxCount = Infinity
Expand Down Expand Up @@ -234,12 +242,12 @@ module.exports = class SqliteCacheStore {
* @type {import('../../types/cache-interceptor.d.ts').default.GetResult}
*/
const result = {
body: Buffer.from(value.body),
body: value.body ? Buffer.from(value.body) : null,
statusCode: value.statusCode,
statusMessage: value.statusMessage,
headers: value.headers ? JSON.parse(value.headers) : undefined,
etag: value.etag ? value.etag : undefined,
vary: value.vary ?? undefined,
vary: value.vary ? JSON.parse(value.vary) : undefined,
cacheControlDirectives: value.cacheControlDirectives
? JSON.parse(value.cacheControlDirectives)
: undefined,
Expand Down Expand Up @@ -293,9 +301,9 @@ module.exports = class SqliteCacheStore {
value.deleteAt,
value.statusCode,
value.statusMessage,
value.headers ? JSON.stringify(value.headers) : null,
value.etag ? value.etag : null,
value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null,
value.headers ?? null,
value.etag ?? null,
value.cacheControlDirectives ?? null,
value.cachedAt,
value.staleAt,
value.deleteAt,
Expand All @@ -311,10 +319,10 @@ module.exports = class SqliteCacheStore {
value.deleteAt,
value.statusCode,
value.statusMessage,
value.headers ? JSON.stringify(value.headers) : null,
value.etag ? value.etag : null,
value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null,
value.vary ? JSON.stringify(value.vary) : null,
value.headers ?? null,
value.etag ?? null,
value.cacheControlDirectives ?? null,
value.vary ?? null,
value.cachedAt,
value.staleAt,
value.deleteAt
Expand Down Expand Up @@ -379,7 +387,7 @@ module.exports = class SqliteCacheStore {
/**
* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key
* @param {boolean} [canBeExpired=false]
* @returns {(SqliteStoreValue & { vary?: Record<string, string[]> }) | undefined}
* @returns {SqliteStoreValue | undefined}
*/
#findValue (key, canBeExpired = false) {
const url = this.#makeValueUrl(key)
Expand Down Expand Up @@ -407,10 +415,10 @@ module.exports = class SqliteCacheStore {
return undefined
}

value.vary = JSON.parse(value.vary)
const vary = JSON.parse(value.vary)

for (const header in value.vary) {
if (!headerValueEquals(headers[header], value.vary[header])) {
for (const header in vary) {
if (!headerValueEquals(headers[header], vary[header])) {
matches = false
break
}
Expand Down
Loading