Skip to content

Commit c6fb6e3

Browse files
Update caching.md
1 parent 6608aae commit c6fb6e3

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

content/techniques/caching.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ Caching is a great and simple **technique** that helps improve your app's perfor
44

55
#### Installation
66

7-
First install [required packages](https://github.com/node-cache-manager/node-cache-manager):
7+
First install required packages:
88

99
```bash
10-
$ npm install cache-manager
10+
$ npm install @nestjs/cache-manager cache-manager
1111
```
1212

13-
> info **Hint** As of version `>=9.2.1`, NestJS is compatible with both `cache-manager` v4 and v5.
14-
1513
> warning **Warning** `cache-manager` version 4 uses seconds for `TTL (Time-To-Live)`. The current version of `cache-manager` (v5) has switched to using milliseconds instead. NestJS doesn't convert the value, and simply forwards the ttl you provide to the library. In other words:
1614
> * If using `cache-manager` v4, provide ttl in seconds
1715
> * If using `cache-manager` v5, provide ttl in milliseconds
@@ -24,7 +22,8 @@ Nest provides a unified API for various cache storage providers. The built-in on
2422
In order to enable caching, import the `CacheModule` and call its `register()` method.
2523

2624
```typescript
27-
import { CacheModule, Module } from '@nestjs/common';
25+
import { Module } from '@nestjs/common';
26+
import { CacheModule } from '@nestjs/cache-manager';
2827
import { AppController } from './app.controller';
2928

3029
@Module({
@@ -42,7 +41,7 @@ To interact with the cache manager instance, inject it to your class using the `
4241
constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}
4342
```
4443

45-
> info **Hint** The `Cache` class is imported from the `cache-manager`, while `CACHE_MANAGER` token from the `@nestjs/common` package.
44+
> info **Hint** The `Cache` class is imported from the `cache-manager`, while `CACHE_MANAGER` token from the `@nestjs/cache-manager` package.
4645
4746
The `get` method on the `Cache` instance (from the `cache-manager` package) is used to retrieve items from the cache. If the item does not exist in the cache, `null` will be returned.
4847

@@ -105,7 +104,8 @@ export class AppController {
105104
To reduce the amount of required boilerplate, you can bind `CacheInterceptor` to all endpoints globally:
106105

107106
```typescript
108-
import { CacheModule, Module, CacheInterceptor } from '@nestjs/common';
107+
import { Module } from '@nestjs/common';
108+
import { CacheModule, CacheInterceptor } from '@nestjs/cache-manager';
109109
import { AppController } from './app.controller';
110110
import { APP_INTERCEPTOR } from '@nestjs/core';
111111

@@ -158,7 +158,7 @@ export class AppController {
158158
}
159159
```
160160

161-
> info **Hint** The `@CacheKey()` and `@CacheTTL()` decorators are imported from the `@nestjs/common` package.
161+
> info **Hint** The `@CacheKey()` and `@CacheTTL()` decorators are imported from the `@nestjs/cache-manager` package.
162162
163163
The `@CacheKey()` decorator may be used with or without a corresponding `@CacheTTL()` decorator and vice versa. One may choose to override only the `@CacheKey()` or only the `@CacheTTL()`. Settings that are not overridden with a decorator will use the default values as registered globally (see [Customize caching](https://docs.nestjs.com/techniques/caching#customize-caching)).
164164

@@ -228,7 +228,8 @@ This service takes advantage of [cache-manager](https://github.com/node-cache-ma
228228
```typescript
229229
import type { RedisClientOptions } from 'redis';
230230
import * as redisStore from 'cache-manager-redis-store';
231-
import { CacheModule, Module } from '@nestjs/common';
231+
import { Module } from '@nestjs/common';
232+
import { CacheModule } from '@nestjs/cache-manager';
232233
import { AppController } from './app.controller';
233234

234235
@Module({

0 commit comments

Comments
 (0)