npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@nestjs-kitchen/cache-manager

v2.0.5

Published

A better caching module for NestJS, fully compatible with @nestjs/cache-manager v3

Downloads

8

Readme

@nestjs-kitchen/cache-manager

NPM Version NPM License codecov

A better caching module for NestJS, fully compatible with @nestjs/cache-manager v3.


Features

  • ✅ Supports caching for regular methods.
  • ✅ Dynamically set cache key and TTL.
  • ✅ Fully compatible with @nestjs/cache-manager API.
  • ✅ 100% test coverage.

Install

$ npm install --save @nestjs-kitchen/cache-manager cache-manager

Usage

Apply CacheModule

import { Module } from '@nestjs/common';
import { CacheModule } from '@nestjs-kitchen/cache-manager';
import { AppController } from './app.controller';

@Module({
  imports: [CacheModule.register()],
  controllers: [AppController],
})
export class AppModule {}

Auto-caching response

@Controller()
@UseInterceptors(CacheInterceptor)
export class AppController {
  @Get()
  findAll(): string[] {
    return [];
  }
}

Auto-caching method result

@Injectable()
export class AppService {
  @CacheResult()
  @Get()
  findAll(): string[] {
    return [];
  }
}

Dynamic cache key & TTL

  • For non-regular methods (HTTP, WebSocket, Microservice, or GraphQL), the callback receives ExecutionContext as the argument.

    @Controller()
    @CacheKey((context: ExecutionContext) => {
      const request = context.switchToHttp().getRequest();
      return `user:${request.params.id}`;
    })
    @CacheTTL((context: ExecutionContext) => {
      return context.switchToHttp().getRequest().query.cacheTime || 60;
    })
    @UseInterceptors(CacheInterceptor)
    export class AppController {
      @Get()
      findAll(): string[] {
        return [];
      }
    }
  • For regular methods, the callback receives the method arguments.

    @Injectable()
    export class AppService {
      @CacheKey((args: any[]) => `user:${args[0]}`)
      @CacheTTL((args: any[]) => 120)
      @CacheResult()
      @Get()
      findAll(): string[] {
        return [];
      }
    }

APIs

CacheModule

Same as @nestjs/cache-manager CacheModule.

CacheInterceptor

Same as @nestjs/cache-manager CacheInterceptor.

CacheResult

Decorator that applies a cache mechanism to regular method, enabling caching for method results.

  • Only applicable to regular methods (non-HTTP/WebSocket/Microservice/GraphQL methods).
  • Compatible with @CacheKey and @CacheTTL for cache control.
  • Automatically disabled when applied to HTTP, WebSocket, Microservice, or GraphQL methods.

Example:

class ExampleService {
  ⁣@CacheResult()
  async fetchData() { ... }

  ⁣@CacheResult()
  ⁣@CacheKey((args: any[]) => `data:${args[0]}`)
  @CacheTTL(60)
  async getItemById(id: number) { ... }
}

CacheKey

Decorator that sets the caching key used to store/retrieve cached items.

Supports both static string keys and dynamic keys via a callback function.

  • When applied to HTTP, WebSocket, Microservice, or GraphQL methods, the callback receives an ExecutionContext as an argument.
  • When applied to regular methods, the callback receives the corresponding method parameters.
  • When applied to a class, only a callback function is allowed.

Example:

@CacheKey('events') // Static key
async fetchData() { ... }

@CacheKey((context: ExecutionContext) => context.switchToHttp().getRequest().url)
async fetchDataWithDynamicKey() { ... }

@CacheKey((args: any[]) => args[0]) // First argument as key
async getItemById(id: string) { ... }

CacheTTL

Decorator that sets the cache TTL (time-to-live) duration for cache expiration.

Supports both static numeric values and dynamic TTL values via a callback function.

  • When applied to HTTP, WebSocket, Microservice, or GraphQL methods, the callback receives an ExecutionContext as an argument.
  • When applied to regular methods, the callback receives the corresponding method parameters.

Eexample:

@CacheTTL(5) // Static TTL of 5 seconds
async fetchData() { ... }

@CacheTTL((context: ExecutionContext) => context.getHandler().name === 'fastQuery' ? 2 : 10)
async fetchDataWithDynamicTTL() { ... }

⁣@CacheTTL((args: any[]) => args[0] > 10 ? 30 : 60) // TTL based on first argument
async getItemById(id: number) { ... }

Reference

For more usage, please see Caching.

License

MIT License