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 ๐Ÿ™

ยฉ 2026 โ€“ย Pkg Stats / Ryan Hefner

cache-panda

v1.2.1

Published

๐Ÿผ A flexible, decorator-based smart cache module for NestJS with TTL, key prefixing, and conditional caching based on method execution time.

Readme

cache-panda

A smart, flexible cache module for NestJS ๐Ÿผ that wraps @nestjs/cache-manager and introduces a flexible @CachePandaSet decorator for conditional, granular, and performance-aware caching.


๐Ÿ“ฆ Installation

npm install cache-panda

Also install peer dependencies (if not already):

npm install @nestjs/cache-manager cache-manager

๐Ÿš€ Features

  • โœ… Drop-in replacement for @nestjs/cache-manager
  • ๐Ÿง  Decorator-based @CachePandaSet() for elegant method-level caching
  • โฑ๏ธ Conditional caching based on method execution time
  • ๐Ÿ”‘ Custom cache key building with prefixes and argument targeting
  • ๐Ÿงฉ Plugs into Redis, memory store, or any cache-manager compatible store
  • ๐Ÿ› ๏ธ Easy to use, fully typed, developer-friendly

๐Ÿ”ง Setup

Register the module in your NestJS app:

// app.module.ts

import { CachePanda } from 'cache-panda';

@Module({
  imports: [
    CachePanda.register({
      ttl: 60000,        // Default TTL in ms
      isGlobal: true,    // Optional: make available globally
      max: 1000,         // Optional max number of keys
    }),
  ],
})
export class AppModule {}

๐Ÿง  Usage

Decorate your methods using @CachePandaSet():

import { Injectable } from '@nestjs/common';
import { CachePandaSet } from 'cache-panda';

@Injectable()
export class MyService {
  @CachePandaSet({
    prefix: 'user:',
    name: 'get-profile',
    ttl: 12000,
    argsIndex: [0],
    executionTimeLimit: 20
  })
  async getUserProfile(userId: string) {
    return { id: userId, name: 'Akhil' };
  }
}

๐Ÿ” @CachePandaSet Options

| Option | Type | Description | |-----------------------|------------|---------------------------------------------------------------------| | prefix | string | Key prefix to categorize/group caches | | name? | string | Logical name for the method being cached | | ttl? | number | Optional override for TTL (in ms) | | argsIndex? | number[] | Pick specific method arguments to build the cache key | | executionTimeLimit? | number | Only cache if method takes more than this number of ms |


๐Ÿ”ง Redis Setup

Also install peer dependencies (if not already):

npm install cache-manager-redis-yet

Register the module in your NestJS app:

// app.module.ts

import { CachePanda } from 'cache-panda';
import { redisStore } from 'cache-manager-redis-yet';

@Module({
  imports: [
    CachePanda.registerAsync({
      isGlobal: true,
      useFactory: async () => ({
        store: await redisStore({
          url: 'redis://localhost:6379',
        }),
        ttl: 1000,  // Default TTL for all cache entries in ms
        max: 100,  // Max items to keep in memory
      }),
    }),
  ],
})
export class AppModule {}

๐Ÿงผ Manual Cache Usage

await this.cachingService.setCache('some-key', JSON.stringify(data), 60);
const result = await this.cachingService.getCache('some-key');

await this.cachingService.deleteCache('some-key');
await this.cachingService.clearCache();

Advanced:

await this.cachingService.deleteCacheByKeys(['key1', 'key2']);
await this.cachingService.deleteCacheByKeyPattern('user:');
const keys = await this.cachingService.getKeysByKeyPattern('user:');

๐Ÿ“ˆ Roadmap

  • [x] Initial release with decorator + service
  • [x] TTL and execution-time-based conditional caching
  • [x] Redis and multi-store setup guide
  • [ ] Auto-Invalidation (Cache Busting) decorator
  • [ ] Logging and debug mode support (cache hit vs miss)
  • [ ] CLI tool to inspect and manage cache keys
  • [ ] 100% test cases coverage

๐Ÿ›  Contributing

Contributions are welcome! Open an issue or PR.

Steps:

  1. Fork the repo ๐Ÿด
  2. Create your feature branch (git checkout -b feat/your-feature)
  3. Commit your changes (git commit -am 'feat: add amazing thing')
  4. Push to the branch (git push origin feat/your-feature)
  5. Create a new Pull Request!

๐Ÿ“œ License

MIT ยฉ Akhil Kumar

Designed with โค๏ธ to make NestJS caching smarter, cleaner, and panda-fied.