Skip to content

Commit dac9bd4

Browse files
Merge pull request #2109 from micalevisk/doc-new-feat-on-cachemodule
docs: cover `CacheModule#register` (and so on) optional type argument
2 parents 1c62eab + 187b898 commit dac9bd4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

content/techniques/caching.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,19 @@ class HttpCacheInterceptor extends CacheInterceptor {
217217
218218
#### Different stores
219219
220-
This service takes advantage of [cache-manager](https://github.com/BryanDonovan/node-cache-manager) under the hood. The `cache-manager` package supports a wide-range of useful stores, for example, [Redis](https://github.com/dabroek/node-cache-manager-redis-store) store. A full list of supported stores is available [here](https://github.com/BryanDonovan/node-cache-manager#store-engines). To set up the Redis store, simply pass the package together with corresponding options to the `register()` method.
220+
This service takes advantage of [cache-manager](https://github.com/BryanDonovan/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/BryanDonovan/node-cache-manager#store-engines). To set up the Redis store, simply pass the package together with corresponding options to the `register()` method.
221221
222222
```typescript
223+
import type { ClientOpts as RedisClientOpts } from 'redis'
223224
import * as redisStore from 'cache-manager-redis-store';
224225
import { CacheModule, Module } from '@nestjs/common';
225226
import { AppController } from './app.controller';
226227

227228
@Module({
228229
imports: [
229-
CacheModule.register({
230+
CacheModule.register<RedisClientOpts>({
230231
store: redisStore,
232+
// Store-specify configuration:
231233
host: 'localhost',
232234
port: 6379,
233235
}),
@@ -295,6 +297,8 @@ CacheModule.registerAsync({
295297
296298
This works the same as `useClass` with one critical difference - `CacheModule` will lookup imported modules to reuse any already-created `ConfigService`, instead of instantiating its own.
297299
300+
> info **Hint** `CacheModule#register` and `CacheModule#registerAsync` and `CacheOptionsFactory` has an optional generic (type argument) to narrow down store-specific configuration options, making it type safe.
301+
298302
#### Example
299303
300304
A working example is available [here](https://github.com/nestjs/nest/tree/master/sample/20-cache).

0 commit comments

Comments
 (0)