#Cache Interceptor Not Working

8 messages · Page 1 of 1 (latest)

verbal oracle
#

I'm trying to figure out why my cache interceptor isn't working. I've verified Redis is accessible by making a dummy controller and connecting to redis with it.

core.module.ts:

import { MongooseModule } from '@nestjs/mongoose';
import { ApiConfigService } from 'src/common/service/api-config.service';

@Module({
  imports: [
    CacheModule.registerAsync({
      imports: [CoreModule],
      inject: [ApiConfigService],
      isGlobal: true,
      useFactory: async (config: ApiConfigService) => ({
        store: require('cache-manager-redis-store'),
        host: '127.0.0.1',
        port: '6379',
        no_ready_check: true,
      }),
    }),
  ],
})
export class CoreModule {}

app.module.ts:

@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: ['.env.development.local', '.env.development'],
      isGlobal: true,
      load: [configuration],
    }),
    CoreModule,
  ],
  controllers: [AppController],
  providers: [AppService, ApiConfigService],
})
export class AppModule {}

config.controller.ts:

import {
  CacheInterceptor,
  CACHE_MANAGER,
  CacheKey,
  CacheTTL,
  Controller,
  Get,
  UseInterceptors,
} from '@nestjs/common';
import { ConfigsService } from './configs.service';

@Controller('configs')
export class ConfigsController {
  constructor(private readonly configsService: ConfigsService) {}

  fakeModel: any = {
    id: 1,
    name: 'John Doeeee',
    email: '[email protected]',
    phone: '123456789',
    address: '123 Main St',
    createdAt: new Date(),
  };

  @Get()
  @UseInterceptors(CacheInterceptor)
  @CacheTTL(10000)
  findAll() {
    // return this.configsService.findAll();
    return new Promise((resolve, _) => {
      setTimeout(() => {
        resolve(this.fakeModel);
      }, 2000);
    });
  }
}
oak sedge
#

Got a reproduction showing it not working?

oak sedge
#

A screen cast won't do much to help here

verbal oracle
#

Oh interesting, sure let me put this together for you

verbal oracle
#

I sorted it out due to you asking for the minimum reproduction

#

Thanks a lot man, you're the true hero