Skip to content

Commit ab780a7

Browse files
JeanMechemmalerba
authored andcommitted
docs: add info about disabling request caching (angular#64216)
fixes angular#64210 PR Close angular#64216
1 parent e403078 commit ab780a7

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

adev/src/content/guide/ssr.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,46 @@ bootstrapApplication(AppComponent, {
337337
});
338338
```
339339

340+
### Disabling caching
341+
342+
You can disable HTTP caching of requests sent from the server either globally or individually.
343+
344+
#### Globally
345+
346+
To disable caching for all requests in your application, use the `withNoHttpTransferCache` feature:
347+
348+
```ts
349+
import { bootstrapApplication, provideClientHydration, withNoHttpTransferCache } from '@angular/platform-browser';
350+
351+
bootstrapApplication(AppComponent, {
352+
providers: [
353+
provideClientHydration(withNoHttpTransferCache())
354+
]
355+
});
356+
```
357+
358+
You can also selectively disable caching for certain requests using the [`filter`](api/common/http/HttpTransferCacheOptions) option in `withHttpTransferCacheOptions`. For example, you can disable caching for a specific API endpoint:
359+
360+
```ts
361+
import { bootstrapApplication, provideClientHydration, withHttpTransferCacheOptions } from '@angular/platform-browser';
362+
363+
bootstrapApplication(AppComponent, {
364+
providers: [
365+
provideClientHydration(withHttpTransferCacheOptions({
366+
filter: (req) => !req.url.includes('/api/sensitive-data')
367+
}))
368+
]
369+
});
370+
```
371+
372+
#### Individually
373+
374+
To disable caching for an individual request, you can specify the [`transferCache`](api/common/http/HttpRequest#transferCache) option in an `HttpRequest`.
375+
376+
```ts
377+
httpClient.get('/api/sensitive-data', { transferCache: false });
378+
```
379+
340380
## Configuring a server
341381

342382
### Node.js

0 commit comments

Comments
 (0)