UNPKG

nuxt

Version:

Nuxt is a free and open-source framework with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with Vue.js.

25 lines (24 loc) 879 B
import { defineDriver } from "unstorage"; import fsDriver from "unstorage/drivers/fs-lite"; import lruCache from "unstorage/drivers/lru-cache"; const normalizeFsKey = (item) => item.replaceAll(":", "_"); export default defineDriver((opts) => { const fs = fsDriver({ base: opts.base }); const lru = lruCache({ max: 1e3 }); return { ...fs, // fall back to file system - only the bottom three methods are used in renderer async setItem(key, value, opts2) { await Promise.all([ fs.setItem(normalizeFsKey(key), value, opts2), lru.setItem(key, value, opts2) ]); }, async hasItem(key, opts2) { return await lru.hasItem(key, opts2) || await fs.hasItem(normalizeFsKey(key), opts2); }, async getItem(key, opts2) { return await lru.getItem(key, opts2) || await fs.getItem(normalizeFsKey(key), opts2); } }; });