title: Caching return value from a service method
body: <p>I am using nestjs and have just installed the <code>cache-manager</code> module and are trying to cache a response from a service call.</p>
  
  <p>I register the cache module in a sample module (sample.module.ts):</p>
  
  <pre><code>import { CacheInterceptor, CacheModule, Module } from '@nestjs/common';
  import { SampleService } from './sample.service';
  import { APP_INTERCEPTOR } from '@nestjs/core';
  import * as redisStore from 'cache-manager-redis-store';
  
  
  @Module({
    imports: [
      CacheModule.register({
        ttl: 10,
        store: redisStore,
        host: 'localhost',
        port: 6379,
      }),
   ],
   providers: [
     SampleService,
     {
       provide: APP_INTERCEPTOR,
       useClass: CacheInterceptor,
     }
   ],
   exports: [SampleService],
  })
  export class SampleModule {}
  </code></pre>
  
  <p>Then in my service (sample.service.ts):</p>
  
  <pre><code>@Injectable()
  export class SampleService {
    @UseInterceptors(CacheInterceptor)
    @CacheKey('findAll')
    async findAll() {
      // Make external API call
    }
  }
  </code></pre>
  
  <p>Looking at redis I can see that nothing is cached for the service method call. If I use the same approach with a controller, then everything works fine and I can see the cached entry in my redis database. I am thinking that there is no way out of the box to cache individual service method calls in nestjs.</p>
  
  <p>Reading the <a href="https://docs.nestjs.com/techniques/caching" rel="nofollow noreferrer"><code>documentation</code></a> it seems that I am only able to use this approach for controllers, microservices and websockets, but not ordinary services?</p>