Skip to content

Commit e524bfe

Browse files
committed
feat!: add server cache binding
1 parent fae96d4 commit e524bfe

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

playground/server/api/cached.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default cachedEventHandler(async (event) => {
2+
return {
3+
now: Date.now()
4+
}
5+
}, {
6+
maxAge: 10
7+
})

src/module/index.ts

+17
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ export default defineNuxtModule<ModuleOptions>({
7979
version
8080
})
8181

82+
// Add Server caching (Nitro)
83+
nuxt.options.nitro = defu(nuxt.options.nitro, {
84+
storage: {
85+
cache: {
86+
driver: 'cloudflare-kv-binding',
87+
binding: 'CACHE',
88+
base: 'cache'
89+
}
90+
},
91+
devStorage: {
92+
cache: {
93+
driver: 'fs',
94+
base: join(rootDir, '.data/cache')
95+
}
96+
}
97+
})
98+
8299
// nuxt prepare or production mode, stop here
83100
if (nuxt.options._prepare || !nuxt.options.dev) {
84101
return

src/module/utils.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ export function generateWrangler() {
33
{ binding = "DB", database_name = "default", database_id = "default" },
44
]
55
kv_namespaces = [
6-
{ binding = "KV", id = "user_default" },
7-
{ binding = "CONFIG", id = "config_default" },
6+
{ binding = "KV", id = "kv_default" },
7+
{ binding = "CACHE", id = "cache_default" },
88
]
99
r2_buckets = [
1010
{ binding = "BLOB", bucket_name = "default" },

0 commit comments

Comments
 (0)