Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=true
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ class MemoryCacheStore {
if (!entries) return undefined

const now = Date.now()
const entry = entries.find((entry) => (
entry.deleteAt > now &&
(entry.vary == null || Object.keys(entry.vary).every(headerName => entry.vary[headerName] === key.headers?.[headerName]))
))
const entry = findEntry(key, entries, now)

return entry == null
? undefined
Expand All @@ -105,6 +102,7 @@ class MemoryCacheStore {
etag: entry.etag,
cacheTags: entry.cacheTags,
cachedAt: entry.cachedAt,
vary: entry.vary,
staleAt: entry.staleAt,
deleteAt: entry.deleteAt,
cacheControlDirectives: entry.cacheControlDirectives
Expand Down Expand Up @@ -174,7 +172,7 @@ class MemoryCacheStore {
}

#saveEntry (key, entry) {
const existingEntry = this.get(key)
const existingEntry = findEntry(key, this.#getEntries(key) || [], Date.now())
if (existingEntry) {
this.#deleteEntry(key, existingEntry)
}
Expand Down Expand Up @@ -354,4 +352,13 @@ class MemoryCacheStore {
}
}

function findEntry (key, entries, now) {
const entry = entries.find((entry) => (
entry.deleteAt > now &&
(entry.vary == null || Object.keys(entry.vary).every(headerName => entry.vary[headerName] === key.headers?.[headerName]))
))
return entry
}


module.exports = MemoryCacheStore
118 changes: 76 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "Platformatic Inc. <oss@platformatic.dev> (https://platformatic.dev)",
"license": "Apache-2.0",
"devDependencies": {
"@sinonjs/fake-timers": "^14.0.0",
"borp": "^0.18.0",
"undici": "^7.1.0"
}
Expand Down
Loading
Loading