Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dynamic runtimeCacheStorage #179

Open
tberk opened this issue Mar 18, 2024 · 2 comments
Open

Support dynamic runtimeCacheStorage #179

tberk opened this issue Mar 18, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@tberk
Copy link

tberk commented Mar 18, 2024

Hello currently I set runtime cache storage as so:

ogImage: {   
    runtimeCacheStorage: {
      driver: 'redis',
      host: process.env.NUXT_REDIS_HOST,
      port: 6379,
      ttlSeconds: 60 * 60 * 24 * 3,
      base: 'best-og',
      password: process.env.NUXT_REDIS_PASSWORD,
    },
  }

I also have a nitro plugin to register redis storage (Independent of og:image config)

export default defineNitroPlugin(() => {
  const storage = useStorage()
  const config = useRuntimeConfig()

  const driver = redisDriver({
    base: config.redis.base,
    host: config.redis.host,
    port: 6379,
    ttl: 60 * 60 * 24 * 3, // 3 days
    password: config.redis.password,
  })

  // Mount driver
  storage.mount('redis', driver)

  // https://nitro.unjs.io/guide/cache
  // Use redis on cache instead of memory
  await storage.unmount('cache')
  storage.mount('cache', driver)
})

Module works fine with above config however I was wondering if there is a better way of doing it.

@harlan-zw
Copy link
Collaborator

Hi, thanks for the issue (sorry for the delay). This is a great question.

Technically you should just be able to do storage.mount('/cache/nuxt-og-image', driver) (the default cache path) within your runtime config and omit runtimeCacheStorage if you want to configure it like that.

Is there any particular reason you're creating the driver yourself instead of just doing it in the config though?

@tberk
Copy link
Author

tberk commented Jul 13, 2024

Hello, thanks for the answer.

The reason is the same actually, to get the runtime config when creating the driver. Here is the reference: https://nitro.unjs.io/guide/storage#runtime-configuration

@harlan-zw harlan-zw changed the title Is it possible to use runtime config for runtimeCacheStorage? Support dynamic runtimeCacheStorage Sep 10, 2024
@harlan-zw harlan-zw added the enhancement New feature or request label Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants