Skip to content

Caching

Arun Prakash edited this page Sep 21, 2025 · 2 revisions

🧠 Caching (Optional)

Speed up repeated GET calls with a simple read‑through/write‑through cache.

Enable cache via bootstrapper

final client = WordpressClient(
  baseUrl: Uri.parse('https://example.com/wp-json/wp/v2'),
  bootstrapper: (b) => b
    .withCache(
      ttl: const Duration(minutes: 5), // default: 1 minute
      // cache: MyCustomCacheManager(), // optional custom store
      // clearOnWrite: false,           // keep cache on POST/PUT/DELETE
    )
    .build(),
);

How it works

  • Applies to GET endpoints (list/retrieve/custom GET).
  • Default store is in‑memory. Provide your own by implementing ICacheManager<WordpressRawResponse>.
  • After a successful write (POST/PUT/PATCH/DELETE), cache is cleared by default to avoid stale data. Toggle via clearOnWrite.

Custom store

class MyStore implements ICacheManager<WordpressRawResponse> {
  // implement put/get/evict/clear as needed
}

Pair caching with the ParallelWordpress features for very fast, paginated reads.

Clone this wiki locally