You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/techniques/caching.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,12 @@ Caching is a great and simple **technique** that helps improve your app's perfor
4
4
5
5
#### Installation
6
6
7
-
First install [required packages](https://github.com/node-cache-manager/node-cache-manager):
7
+
First install required packages:
8
8
9
9
```bash
10
-
$ npm install cache-manager
10
+
$ npm install @nestjs/cache-manager cache-manager
11
11
```
12
12
13
-
> info **Hint** As of version `>=9.2.1`, NestJS is compatible with both `cache-manager` v4 and v5.
14
-
15
13
> 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:
16
14
> * If using `cache-manager` v4, provide ttl in seconds
17
15
> * 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
24
22
In order to enable caching, import the `CacheModule` and call its `register()` method.
> 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.
46
45
47
46
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.
48
47
@@ -105,7 +104,8 @@ export class AppController {
105
104
To reduce the amount of required boilerplate, you can bind `CacheInterceptor` to all endpoints globally:
> 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.
162
162
163
163
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)).
164
164
@@ -228,7 +228,8 @@ This service takes advantage of [cache-manager](https://github.com/node-cache-ma
228
228
```typescript
229
229
import type { RedisClientOptions } from 'redis';
230
230
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';
0 commit comments