Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
@nestjs/cache-manager
Advanced tools
Nest - modern, fast, powerful node.js web framework (@cache-manager)
@nestjs/cache-manager is a caching module for the NestJS framework that provides a simple and efficient way to manage caching in your application. It supports various caching stores and strategies, making it flexible and powerful for different use cases.
Basic Caching
This feature allows you to set up basic caching in your NestJS application. You can configure the time-to-live (ttl) and the maximum number of items in the cache.
const { CacheModule } = require('@nestjs/cache-manager');
const { Module } = require('@nestjs/common');
@Module({
imports: [
CacheModule.register({
ttl: 5, // seconds
max: 10, // maximum number of items in cache
}),
],
})
export class AppModule {}
Using Cache Interceptors
This feature demonstrates how to use cache interceptors to automatically cache the response of a controller method. This can be useful for reducing the load on your server by caching frequently requested data.
const { CacheInterceptor, CacheModule } = require('@nestjs/cache-manager');
const { Controller, Get, UseInterceptors } = require('@nestjs/common');
@Controller('cats')
@UseInterceptors(CacheInterceptor)
export class CatsController {
@Get()
findAll() {
return [{ name: 'Tom' }, { name: 'Jerry' }];
}
}
Custom Cache Store
This feature allows you to use a custom cache store, such as Redis, for your caching needs. This can be useful for distributed caching scenarios where you need a more robust and scalable caching solution.
const { CacheModule } = require('@nestjs/cache-manager');
const { Module } = require('@nestjs/common');
const * as redisStore from 'cache-manager-redis-store';
@Module({
imports: [
CacheModule.register({
store: redisStore,
host: 'localhost',
port: 6379,
}),
],
})
export class AppModule {}
cache-manager is a popular caching library for Node.js that supports multiple storage engines, including in-memory, Redis, and more. It provides a flexible and powerful API for managing cache, similar to @nestjs/cache-manager, but it is not specific to the NestJS framework.
node-cache is a simple and efficient in-memory caching solution for Node.js. It is easy to use and provides basic caching functionalities. However, it lacks the advanced features and integrations provided by @nestjs/cache-manager.
redis is a powerful in-memory data structure store that can be used as a cache, database, and message broker. While it is not a caching library per se, it is often used in conjunction with caching libraries like @nestjs/cache-manager to provide a robust caching solution.
A progressive Node.js framework for building efficient and scalable server-side applications.
cache-manager module for Nest originally published as part of the @nestjs/common
package. This package is a drop-in replacement for the deprecated CacheModule
.
$ npm i --save @nestjs/cache-manager cache-manager
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
Nest is MIT licensed.
FAQs
Nest - modern, fast, powerful node.js web framework (@cache-manager)
The npm package @nestjs/cache-manager receives a total of 456,770 weekly downloads. As such, @nestjs/cache-manager popularity was classified as popular.
We found that @nestjs/cache-manager demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.