Skip to content

Cannot use composable useRuntimeConfig() inside multiCache.ServerOptions.ts #116

@niddu85

Description

@niddu85

I migrated from version 3.1.1 to 4.0.2 of nuxt-multi-cache following the migration guide, but now i'm not able to use composable useRuntimeConfig in \server\multiCache.serverOptions.ts anymore.
When i run my project with npm run dev i got the error:

[nuxt] A composable that requires access to the Nuxt instance was called outside of a plugin, Nuxt hook, Nuxt middleware, or Vue setup function. This is probably not a Nuxt bug. Find out more at https://nuxt.com/docs/guide/concepts/auto-imports#vue-and-nuxt-composables`.`

While if i build and release the project it works without problems.

I use it to get the redis connection parameters.
Is there any other way to use it?

import { defineMultiCacheOptions } from "nuxt-multi-cache/server-options";
import redisDriver from "unstorage/drivers/redis";
import type { RedisOptions } from "unstorage/drivers/redis";


const config = useRuntimeConfig();

let redisDriverOpts: RedisOptions;
 
  redisDriverOpts = {
    db: parseInt(config.REDIS_CACHE_DB),
    host: config.REDIS_CACHE_HOST,
    port: parseInt(config.REDIS_CACHE_PORT),
  };
 
export default defineMultiCacheOptions(() => {
  return {
    route: {
      storage: {
        driver: redisDriver({
          ...redisDriverOpts,
          base: `${config.REDIS_CACHE_PREFIX}:route:`,
        }),
      },
    },
    data: {
      storage: {
        driver: redisDriver({
          ...redisDriverOpts,
          base: `${config.REDIS_CACHE_PREFIX}:data:`,
        }),
      },
    },
  };
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions