So, I have a globally defined Redis cache manager in the apps main module:
@Module({
imports: [
ConfigModule.forRoot(),
DbModule.forRoot(),
CacheModule.registerAsync({
imports: [ConfigModule.forRoot()],
useFactory: async (
configService: ConfigService,
): Promise<CacheModuleOptions> => ({
isGlobal: true,
ttl: parseInt(configService.get('CACHE_DEFAULT_TTL', '3600')),
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
store: async () =>
await redisStore({
// Store-specific configuration:
url: configService.get('REDIS_URL', 'redis://localhost:6379'),
}),
}),
inject: [ConfigService],
}),
RandomModule,
],
providers: [Logger, ConfigService, RandomService],
})
And then I have the RandomModule that has services that should use this global cache, and per instructions, I added the CacheModule to the imports there <- see below
@Module({
imports: [ConfigModule.forRoot(), DbModule.forRoot(), CacheModule.register()],
providers: [
ConfigService,
Logger,
],
exports: [
RandomService,
],
})
This runs fine, but as it turns out, the cache instance in the RandomModule is not the same as the one in the main app module. The one in the main app, used the Redis cache, the one in the RandomModule does not, it's just a memory cache.
If as, as per instructions for global usage, do not import the CacheModule, I get a complaint that the CACHE_MANAGER cannot be resolved... So that doesn't work either.
So, how do I do this?