Repository navigation
Request Deduplication and Concurrency
Two opt-in client settings that control how many network calls are made and how many run at once.
final client = WordpressClient.forSite(
siteUrl: siteUrl,
bootstrapper: (b) => b
.withRequestDeduplication() // identical concurrent GETs share one call
.withMaxConcurrentRequests(6) // at most 6 requests in flight
.build(),
);When several parts of an app ask for the same thing at the same time (two widgets both loading /posts/42 on startup), only the first request goes to the network. The others wait for it and receive the same response.
final results = await Future.wait([
client.posts.retrieve(RetrievePostRequest(id: 42)),
client.posts.retrieve(RetrievePostRequest(id: 42)), // shares the call above
]);Requests are shared when they are GETs with the same URL, query parameters, headers, authorization and requireAuth. They are never shared when they:
- are not
GET, - carry a
CancelToken(one caller could cancel the call for the others), or - carry
WordpressEvents(progress callbacks belong to one caller).
Sharing only covers requests in flight: once the response arrives the entry is removed, and a later identical call goes out again. For reuse over time use the cache. The two work together: a de-duplicated call still passes through the cache middleware once.
The shared response is one object. Do not mutate its data in place.
withMaxConcurrentRequests(n) lets at most n requests run at the same time, per client. Further requests wait in order and start as slots free up. The limit applies to everything the client sends: REST, GraphQL, Abilities, batches, parallel requests and retries of the same call (a retry keeps its slot).
Use it to be gentle with shared hosting or to avoid exhausting sockets on mobile. n must be at least 1 (ArgumentError otherwise). Without the setting nothing is limited.
Both settings live in the client configuration, so they can be changed with reconfigure(bootstrapper: ...) and they are not shared between clients.
Getting started
- Usage
- Bootstrap and Configuration
- Authorization
- Browser Sign-In
- WordPress.com and Jetpack
- Multisite
- Supported REST Methods
Requests and data
- Sending Requests
- Error Handling and Responses
- Fluent Queries
- Interfaces and Extensions
- Custom Post Types
- Model Generator
- Meta and ACF
- Concurrent Edits
- Batch Requests
- Embed and Fields
- Pagination and Finders
- Parallel Requests
- Streaming and Polling
- Pattern Directory Items
Behaviour
- Retries
- Caching
- Request De-duplication and Concurrency
- Middlewares
- Logging
- Offline Write Queue
- Events and Statistics
Other APIs
Extend and test
Reference