Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(nuxt): use fallthrough cache for prerender (#26104)
- Loading branch information
Showing
4 changed files
with
39 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { defineDriver } from 'unstorage' | ||
import fsDriver from 'unstorage/drivers/fs-lite' | ||
import lruCache from 'unstorage/drivers/lru-cache' | ||
|
||
// Ensure we don't try to write/read from directory index for `/` paths | ||
const normalizeFsKey = (item: string) => item.indexOf(':') === -1 ? `${item}:index` : item | ||
|
||
export default defineDriver((opts: { base: string }) => { | ||
const fs = fsDriver({ base: opts.base }) | ||
const lru = lruCache({ max: 1000 }) | ||
|
||
return { | ||
...fs, // fall back to file system - only the bottom three methods are used in renderer | ||
async setItem (key, value, opts) { | ||
await Promise.all([ | ||
fs.setItem(normalizeFsKey(key), value, opts), | ||
lru.setItem(key, value, opts) | ||
]) | ||
}, | ||
async hasItem (key, opts) { | ||
return await lru.hasItem(key, opts) || await fs.hasItem(normalizeFsKey(key), opts) | ||
}, | ||
async getItem (key, opts) { | ||
return await lru.getItem(key, opts) || await fs.getItem(normalizeFsKey(key), opts) | ||
}, | ||
} | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.