Skip to content

Commit c79795d

Browse files
Merge pull request #2066 from Zerotask/patch-7
docs(cache): add info about using the module globally
2 parents bfe8192 + 53f4628 commit c79795d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

content/techniques/caching.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export class AppModule {}
118118

119119
#### Customize caching
120120

121-
All cached data has its own expiration time (TTL). To customize default values, pass the options object to the `register()` method.
121+
All cached data has its own expiration time ([TTL](https://en.wikipedia.org/wiki/Time_to_live)). To customize default values, pass the options object to the `register()` method.
122122

123123
```typescript
124124
CacheModule.register({
@@ -127,6 +127,16 @@ CacheModule.register({
127127
});
128128
```
129129

130+
#### Use module globally
131+
132+
When you want to use `CacheModule` in other modules, you'll need to import it (as is standard with any Nest module). Alternatively, declare it as a [global module](https://docs.nestjs.com/modules#global-modules) by setting the options object's `isGlobal` property to `true`, as shown below. In that case, you will not need to import `CacheModule` in other modules once it's been loaded in the root module (e.g., `AppModule`).
133+
134+
```typescript
135+
CacheModule.register({
136+
isGlobal: true,
137+
});
138+
```
139+
130140
#### Global cache overrides
131141

132142
While global cache is enabled, cache entries are stored under a `CacheKey` that is auto-generated based on the route path. You may override certain cache settings (`@CacheKey()` and `@CacheTTL()`) on a per-method basis, allowing customized caching strategies for individual controller methods. This may be most relevant while using [different cache stores.](https://docs.nestjs.com/techniques/caching#different-stores)

0 commit comments

Comments
 (0)