Nest.js caching: Error: "null" is not a cacheable value

Viewed 23

I have the following cache-config.service.ts with isCacheableValue function as here:

...

@Injectable()
export class CacheConfigService implements CacheOptionsFactory {
  host: string;
  ...

  constructor(private configService: ConfigService<RedisConfig, true>) {
    this.host = this.configService.getOrThrow<string>('redis.host', {
      infer: true,
    });
    ...
  }

  createCacheOptions(): CacheModuleOptions<ClientOpts> {
    return {
      store: redisStore,
      host: this.host,
      isCacheableValue(value) {
        return value !== null && value !== false && value !== undefined;
      },
    };
  }
}

But it crashes on null returned value.

For example, when I call get request on non-existing user at /users/999, it return null and server is crashed with error: Error: "null" is not a cacheable value.

Please help me, what I am doing wrong?

0 Answers
Related