nestjs-async-cache-dedupe
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

Nest Async Cache Dedupe

Publish Package to NPM

English | 中文

A high-performance function call caching and deduplication solution for NestJS, specifically designed to solve performance issues caused by duplicate function calls in high-concurrency scenarios.

Features

  • 🚀 Function-level concurrent call deduplication
  • ⚡️ Support for instant caching (no TTL) and persistent caching
  • 🔄 Automatic handling of concurrent calls with identical parameters
  • 💾 Configurable storage backends (Memory/Redis)
  • 🎯 Seamless integration with NestJS decorator system

Installation

npm install nest-async-cache-dedupe

Quick Start

Register Module

import { AsyncCacheDedupeModule } from 'nest-async-cache-dedupe';

@Module({
  imports: [AsyncCacheDedupeModule.forRoot()],
})
export class AppModule {}

Use Decorator

class SomeService {
  // Instant cache example (concurrent deduplication)
  @AsyncCacheDedupe()
  async fetchData(id: string) {
    // Multiple concurrent calls with same parameters will only execute once
    return await this.heavyOperation(id);
  }

  // Persistent cache example
  @AsyncCacheDedupe({
    ttl: 60, // Cache for 60 seconds
  })
  async getUserProfile(userId: string) {
    return await this.userRepository.findOne(userId);
  }
}

Use Cases

  1. Concurrent Request Optimization: Execute actual operation only once when multiple requests call the same function with identical parameters
  2. Core Business Function Reuse: Cache frequently called core business functions
  3. API Performance Optimization: Reduce duplicate calls to databases or external services

Advanced Configuration

Redis Storage Configuration

AsyncCacheDedupeModule.forRoot({
  storage: {
    type: 'redis',
    options: {
      host: 'localhost',
      port: 6379
    }
  }
})

License

MIT Licensed

Package Sidebar

Install

npm i nestjs-async-cache-dedupe

Weekly Downloads

1

Version

1.0.1

License

MIT

Unpacked Size

13.5 kB

Total Files

8

Last publish

Collaborators

  • zhangchao19971004