How to setup cache storage to change in runtime ? #2944
Answered
by
cjpearson
geminigeek
asked this question in
Q&A
-
hi, this is regarding this section https://nitro.build/guide/cache#caching-route-rules , i am using nuxt 3. example from the link
|
Beta Was this translation helpful? Give feedback.
Answered by
cjpearson
Dec 19, 2024
Replies: 1 comment 1 reply
-
Instead of defining the storage in the nuxt.config, you can create a nitro plugin which mounts a storage based on some runtime configuration. Something like this: import redis from "unstorage/drivers/redis";
export default defineNitroPlugin(() => {
const storage = useStorage();
const config = useRuntimeConfig();
storage.mount(
"/redis",
redis({
url: config.redisUrl
})
);
}); export default defineNuxtConfig({
runtimeConfig: {
redisUrl: '' // set in .env with NUXT_REDIS_URL
},
routeRules: {
"/blog/**": { cache: { maxAge: 60 * 60, base: "redis" } },
},
}); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
geminigeek
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of defining the storage in the nuxt.config, you can create a nitro plugin which mounts a storage based on some runtime configuration.
#1161 (comment)
Something like this: