diff --git a/content/techniques/caching.md b/content/techniques/caching.md index b272d183a3..f7f79d951f 100644 --- a/content/techniques/caching.md +++ b/content/techniques/caching.md @@ -229,32 +229,38 @@ class HttpCacheInterceptor extends CacheInterceptor { #### Different stores -This service takes advantage of [cache-manager](https://github.com/node-cache-manager/node-cache-manager) under the hood. The `cache-manager` package supports a wide-range of useful stores, for example, [Redis store](https://github.com/dabroek/node-cache-manager-redis-store). A full list of supported stores is available [here](https://github.com/node-cache-manager/node-cache-manager#store-engines). To set up the Redis store, simply pass the package together with corresponding options to the `register()` method. +This service takes advantage of [cache-manager](https://github.com/node-cache-manager/node-cache-manager) under the hood. The `cache-manager` package supports a wide-range of useful stores, for example, [Redis store](https://github.com/node-cache-manager/node-cache-manager-redis-yet) official package for node-cache-manager. A full list of supported stores is available [here](https://github.com/node-cache-manager/node-cache-manager#store-engines). To set up the Redis store, use the `registerAsync()` method to initialize the store, as follows: ```typescript -import type { RedisClientOptions } from 'redis'; -import * as redisStore from 'cache-manager-redis-store'; +import { redisStore } from 'cache-manager-redis-yet'; import { Module } from '@nestjs/common'; -import { CacheModule } from '@nestjs/cache-manager'; +import { CacheModule, CacheStore } from '@nestjs/cache-manager'; import { AppController } from './app.controller'; @Module({ imports: [ - CacheModule.register({ - store: redisStore, - - // Store-specific configuration: - host: 'localhost', - port: 6379, - }), + CacheModule.registerAsync({ + useFactory: async () => { + const store = await redisStore({ + socket: { + host: 'localhost', + port: 6379, + }, + }); + + return { + store: store as unknown as CacheStore, + ttl: 3 * 60000, // 3 minutes (milliseconds) + }; + } + }) ], controllers: [AppController], }) export class AppModule {} ``` -> warning**Warning** `cache-manager-redis-store` does not support redis v4. In order for the `ClientOpts` interface to exist and work correctly you need to install the -> latest `redis` 3.x.x major release. See this [issue](https://github.com/dabroek/node-cache-manager-redis-store/issues/40) to track the progress of this upgrade. +> warning**Warning** `cache-manager-redis-yet` requires the ttl to be passed directly rather than as module options. #### Async configuration