Skip to content

Commit e29411a

Browse files
authored
fix(cache): handle cache keys with . (#196)
1 parent aed88b1 commit e29411a

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/runtime/cache/server/api/_hub/cache/[...key].get.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ export default eventHandler(async (event) => {
1111

1212
const key = getRouterParam(event, 'key') || ''
1313
// If ends with an extension
14-
if (/\.[a-z0-9]+$/i.test(key)) {
15-
return await useStorage('cache:nitro').getItem(key)
14+
if (/\.[a-z0-9]{2,5}$/i.test(key)) {
15+
const item = await useStorage('cache:nitro').getItem(key)
16+
if (item) {
17+
return item
18+
}
19+
// Ignore if item is not found, treat the key as a prefix and look for children
1620
}
1721
const storage = useStorage(`cache:nitro:${key}`)
1822
const keys = await storage.getKeys()

src/runtime/cache/server/api/_hub/cache/batch-delete.post.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export default eventHandler(async (event) => {
1717
// delete with batch of 25 keys
1818
do {
1919
const keysToDelete = keys.splice(0, 25)
20-
await Promise.all(keysToDelete.map(storage.removeItem))
20+
await Promise.all(keysToDelete.map(key => storage.removeItem(key)))
2121
} while (keys.length)
2222

2323
return sendNoContent(event)

0 commit comments

Comments
 (0)