diff --git a/src/runtime/cache/server/api/_hub/cache/[...key].delete.ts b/src/runtime/cache/server/api/_hub/cache/[...key].delete.ts index eba77ce1..bbec0715 100644 --- a/src/runtime/cache/server/api/_hub/cache/[...key].delete.ts +++ b/src/runtime/cache/server/api/_hub/cache/[...key].delete.ts @@ -15,7 +15,7 @@ export default eventHandler(async (event) => { message: 'Invalid key' }) } - const storage = useStorage('cache:nitro') + const storage = useStorage('cache') await storage.removeItem(key) return sendNoContent(event) diff --git a/src/runtime/cache/server/api/_hub/cache/[...key].get.ts b/src/runtime/cache/server/api/_hub/cache/[...key].get.ts index fa66f98e..b34ac269 100644 --- a/src/runtime/cache/server/api/_hub/cache/[...key].get.ts +++ b/src/runtime/cache/server/api/_hub/cache/[...key].get.ts @@ -12,13 +12,13 @@ export default eventHandler(async (event) => { const key = getRouterParam(event, 'key') || '' // If ends with an extension if (/\.[a-z0-9]{2,5}$/i.test(key)) { - const item = await useStorage('cache:nitro').getItem(key) + const item = await useStorage('cache').getItem(key) if (item) { return item } // Ignore if item is not found, treat the key as a prefix and look for children } - const storage = useStorage(`cache:nitro:${key}`) + const storage = useStorage(`cache:${key}`) const keys = await storage.getKeys() const stats = { diff --git a/src/runtime/cache/server/api/_hub/cache/batch-delete.post.ts b/src/runtime/cache/server/api/_hub/cache/batch-delete.post.ts index 8eca594e..65fa7015 100644 --- a/src/runtime/cache/server/api/_hub/cache/batch-delete.post.ts +++ b/src/runtime/cache/server/api/_hub/cache/batch-delete.post.ts @@ -13,7 +13,7 @@ export default eventHandler(async (event) => { keys: z.array(z.string().min(1)).min(1) }).parse) - const storage = useStorage('cache:nitro') + const storage = useStorage('cache') // delete with batch of 25 keys do { const keysToDelete = keys.splice(0, 25) diff --git a/src/runtime/cache/server/api/_hub/cache/clear/[...base].delete.ts b/src/runtime/cache/server/api/_hub/cache/clear/[...base].delete.ts index ff668e8f..b5e386f3 100644 --- a/src/runtime/cache/server/api/_hub/cache/clear/[...base].delete.ts +++ b/src/runtime/cache/server/api/_hub/cache/clear/[...base].delete.ts @@ -16,7 +16,7 @@ export default eventHandler(async (event) => { }) } - const storage = useStorage(`cache:nitro:${base}`) + const storage = useStorage(`cache:${base}`) const keys = await storage.getKeys() // delete with batch of 25 keys do { diff --git a/src/runtime/cache/server/api/_hub/cache/index.get.ts b/src/runtime/cache/server/api/_hub/cache/index.get.ts index 2f7f35d9..8517f720 100644 --- a/src/runtime/cache/server/api/_hub/cache/index.get.ts +++ b/src/runtime/cache/server/api/_hub/cache/index.get.ts @@ -8,12 +8,9 @@ export default eventHandler(async (event) => { await requireNuxtHubAuthorization(event) requireNuxtHubFeature('cache') - const cache = await useStorage('cache:nitro').getKeys() + const cache = await useStorage('cache').getKeys() - const stats: Record = { - handlers: 0, - functions: 0 - } + const stats: Record = {} for (const key of cache) { if (!key.includes(':')) continue diff --git a/test/cache.test.ts b/test/cache.test.ts index dc5d42b0..044ab6cf 100644 --- a/test/cache.test.ts +++ b/test/cache.test.ts @@ -30,7 +30,7 @@ describe('KV', async () => { it('Fetch Keys List (empty)', async () => { const result = await $fetch('/api/_hub/cache') - expect(result).toMatchObject({ functions: 0, handlers: 0 }) + expect(result).toMatchObject({}) }) describe('Trigger Cached functions & handlers', () => { @@ -38,13 +38,16 @@ describe('KV', async () => { const result = await $fetch('/api/cached') expect(result).toMatchObject({ hello: 'world' }) - const result2 = await $fetch('/api/_hub/cache') - expect(result2).toMatchObject({ functions: 0, handlers: 1 }) + const entries = await $fetch('/api/_hub/cache') + expect(entries).toMatchObject({ nitro: 1 }) - const handlers = await $fetch('/api/_hub/cache/handlers') + const nitro = await $fetch('/api/_hub/cache/nitro') + expect(nitro).toMatchObject({ cache: [], groups: { handlers: 1 } }) + + const handlers = await $fetch('/api/_hub/cache/nitro/handlers') expect(handlers).toMatchObject({ cache: [], groups: { _: 1 } }) - const handlers_ = await $fetch>('/api/_hub/cache/handlers/_') + const handlers_ = await $fetch>('/api/_hub/cache/nitro/handlers/_') expect(handlers_.cache.length).greaterThan(0) cacheListFields.forEach(key => expect(handlers_.cache[0]).toHaveProperty(key))