Skip to content

Commit

Permalink
fix(cache): smartly overwrite devStorage to handle pre-rendering (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored Oct 14, 2024
1 parent a566d34 commit 03f3572
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,24 @@ export async function setupCache(nuxt: Nuxt) {
storage: {
cache: {
driver,
binding: 'CACHE'
binding: 'CACHE',
base: 'cache'
}
},
devStorage: {
cache: {
driver,
binding: 'CACHE'
}
cache: nuxt.options.dev
// if local development, use KV binding so it respect TTL
? {
driver,
binding: 'CACHE'
}
: {
// Used for pre-rendering
driver: 'fs',
base: join(nuxt.options.rootDir, '.data/cache')
}
}
})
nuxt.hooks.hook('nitro:init', (nitro) => {
nitro.hooks.hook('prerender:config', (config) => {
config.devStorage ||= {}
config.devStorage.cache = {
driver: 'fs',
base: join(nuxt.options.rootDir, '.data/cache')
}
})
})

// Add Server scanning
addServerScanDir(resolve('./runtime/cache/server'))
Expand Down

0 comments on commit 03f3572

Please sign in to comment.