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
+19-13Lines changed: 19 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -229,32 +229,38 @@ class HttpCacheInterceptor extends CacheInterceptor {
229
229
230
230
#### Different stores
231
231
232
-
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.
232
+
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:
233
233
234
234
```typescript
235
-
import type { RedisClientOptions } from 'redis';
236
-
import * as redisStore from 'cache-manager-redis-store';
235
+
import { redisStore } from 'cache-manager-redis-yet';
237
236
import { Module } from '@nestjs/common';
238
-
import { CacheModule } from '@nestjs/cache-manager';
237
+
import { CacheModule, CacheStore } from '@nestjs/cache-manager';
239
238
import { AppController } from './app.controller';
240
239
241
240
@Module({
242
241
imports: [
243
-
CacheModule.register<RedisClientOptions>({
244
-
store: redisStore,
245
-
246
-
// Store-specific configuration:
247
-
host: 'localhost',
248
-
port: 6379,
249
-
}),
242
+
CacheModule.registerAsync({
243
+
useFactory: async () => {
244
+
const store =awaitredisStore({
245
+
socket: {
246
+
host: 'localhost',
247
+
port: 6379,
248
+
},
249
+
});
250
+
251
+
return {
252
+
store: storeasunknownasCacheStore,
253
+
ttl: 3*60000, // 3 minutes (milliseconds)
254
+
};
255
+
}
256
+
})
250
257
],
251
258
controllers: [AppController],
252
259
})
253
260
exportclassAppModule {}
254
261
```
255
262
256
-
> 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
257
-
> 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.
263
+
> warning**Warning** `cache-manager-redis-yet` requires the ttl to be passed directly rather than as module options.
0 commit comments