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