Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docs/examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,21 @@ async function deleteRequest (port = 3001) {
}
```

## Cacheable DNS Lookup
## Production configuration

### Using CacheableLookup to cache DNS lookups in undici
### Using interceptors to add response caching, DNS lookup caching and connection retries

```js
import { Agent } from 'undici'
import CacheableLookup from 'cacheable-lookup';
import { Agent, interceptors, setGlobalDispatcher } from 'undici'

const cacheable = new CacheableLookup(opts)
// Interceptors to add response caching, DNS caching and retrying to the dispatcher
const { cache, dns, retry } = interceptors

const agent = new Agent({
connect: { lookup: cacheable.lookup }
})
const defaultDispatcher = new Agent({
connections: 100, // Limit concurrent kept-alive connections to not run out of resources
headersTimeout: 10_000, // 10 seconds; set as appropriate for the remote servers you plan to connect to
bodyTimeout: 10_000,
}).compose(cache(), dns(), retry())

setGlobalDispatcher(defaultDispatcher) // Add these interceptors to all `fetch` and Undici `request` calls
```
Loading