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

CacheModule in multiple modules not loading the config properly #203

Open
2 of 4 tasks
GustavoKatel opened this issue Nov 10, 2023 · 1 comment
Open
2 of 4 tasks
Labels
bug Something isn't working

Comments

@GustavoKatel
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

I have a helper function that creates the CacheModule dynamically based on some input. This function is called multiple times for different modules that rely on CacheModule.

The CacheModule however is not loading the settings correctly. Only one of the settings set are loaded and applied to all other modules using the same function.

function:

export function createCacheModule(options: CreateCacheModuleOptions) {
  options.inject = [ConfigService, ...(options.inject || [])];

  if (options.useFactory) {
    const inputFactory = options.useFactory;
    options.useFactory = async (configService: ConfigService) => {
      const opts = await inputFactory(configService);
      console.log({ opts });
      return opts;
    };
  }

  return CacheModule.registerAsync(options);
}

expected logs:
image

current logs:
image

in the second screenshot you can see that only the useFactory of AModule gets called and BModule gets the same config from AModule even though they are created differently.

Minimum reproduction code

https://github.com/GustavoKatel/nestjs-cache-module-test

Steps to reproduce

  1. npm ci
  2. npm run start
  3. check the logs

Expected behavior

I expected the ttl and all other settings to be different for in BModule, but insteead BModule got the same settings from AModule (see screenshots above)

Package version

2.1.1

NestJS version

10.2.8

Node.js version

21.1.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@drdreo
Copy link

drdreo commented Jan 17, 2024

I also ran into this. But after upgrading from 10.2.10 --> @nestjs/common@10.3.0 and @nestjs/core@10.3.0.
In thisprovided repo the tests fail , there is also a working branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants