#Cache not initializing

7 messages · Page 1 of 1 (latest)

little saffron
#

Hiya, so I have a service class that looks sort of like this (Minimized to only the important bits):

import type { EventEmitter2 } from '@nestjs/event-emitter';
import type { Cache } from 'cache-manager';
import type { RedisClient } from 'bullmq';
import { CACHE_MANAGER } from '@nestjs/cache-manager';

@Injectable()
export class GameEventStreamService {
    private readonly logger = new Logger(GameEventStreamService.name);
    private cache: RedisClient;

    constructor(
        @Inject(CACHE_MANAGER) private cacheManager: Cache,
        private eventEmitter: EventEmitter2,
    ) {
        cacheManager.stores
            .at(0)
            .store.getClient()
            .then((client) => {
                this.cache = client;
            });
    }
    //...\\
}

And later down the line, when I try to use the this.cache, it returns null/undefined. Why?

#

Specifically further down, there's a method that has this check:

if (!this.cache) {
            this.logger.error('Cache not initialized');
            return [];
        }

Which keeps throwing every time

balmy scarab
#

Not necord related question, please ask #1025199348096700476 here

little saffron
#

Ah, okay.

little saffron
balmy scarab
#

No, away from keyboard rn

little saffron
#

Alright, posted