Skip to content

Commit 03f3572

Browse files
authored
fix(cache): smartly overwrite devStorage to handle pre-rendering (#320)
1 parent a566d34 commit 03f3572

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/features.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,24 @@ export async function setupCache(nuxt: Nuxt) {
158158
storage: {
159159
cache: {
160160
driver,
161-
binding: 'CACHE'
161+
binding: 'CACHE',
162+
base: 'cache'
162163
}
163164
},
164165
devStorage: {
165-
cache: {
166-
driver,
167-
binding: 'CACHE'
168-
}
166+
cache: nuxt.options.dev
167+
// if local development, use KV binding so it respect TTL
168+
? {
169+
driver,
170+
binding: 'CACHE'
171+
}
172+
: {
173+
// Used for pre-rendering
174+
driver: 'fs',
175+
base: join(nuxt.options.rootDir, '.data/cache')
176+
}
169177
}
170178
})
171-
nuxt.hooks.hook('nitro:init', (nitro) => {
172-
nitro.hooks.hook('prerender:config', (config) => {
173-
config.devStorage ||= {}
174-
config.devStorage.cache = {
175-
driver: 'fs',
176-
base: join(nuxt.options.rootDir, '.data/cache')
177-
}
178-
})
179-
})
180179

181180
// Add Server scanning
182181
addServerScanDir(resolve('./runtime/cache/server'))

0 commit comments

Comments
 (0)