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.
- 🚀 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
npm install nest-async-cache-dedupe
import { AsyncCacheDedupeModule } from 'nest-async-cache-dedupe';
@Module({
imports: [AsyncCacheDedupeModule.forRoot()],
})
export class AppModule {}
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);
}
}
- Concurrent Request Optimization: Execute actual operation only once when multiple requests call the same function with identical parameters
- Core Business Function Reuse: Cache frequently called core business functions
- API Performance Optimization: Reduce duplicate calls to databases or external services
AsyncCacheDedupeModule.forRoot({
storage: {
type: 'redis',
options: {
host: 'localhost',
port: 6379
}
}
})
MIT Licensed