Skip to content

Request Deduplication and Concurrency

Arun Prakash edited this page Oct 25, 2026 · 1 revision

Request De-duplication and Concurrency Limit

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(),
);

De-duplication

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.

Concurrency limit

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.

Per client

Both settings live in the client configuration, so they can be changed with reconfigure(bootstrapper: ...) and they are not shared between clients.

Clone this wiki locally