Guide to Caching Init Live Search REST API with Cloudflare Cache Rules

Using the Init Live Search plugin to improve your WordPress site’s search experience? Although already lightweight and optimized, you can further enhance performance by using Cloudflare’s Cache Rules to cache REST API queries like /wp-json/initlise/v1/search. This can dramatically reduce server requests and speed up response times instantly.

Guide to Caching Init Live Search REST API with Cloudflare Cache Rules

Why cache the search REST API?

  • Faster search result response times
  • Reduced CPU and RAM usage on the server
  • Fewer database (MySQL) queries
  • Resource-saving, ideal for high-traffic websites

In addition, caching REST API comes with several “great-free-easy” advantages:

  • Free: Cloudflare’s cache support is free, so no extra infrastructure cost
  • Huge server load reduction: especially when bots crawl, users spam keystrokes, or automated testing tools are active
  • Instant results: for duplicate queries, users receive responses immediately without hitting WordPress again

This is especially effective because Init Live Search already supports backend caching via wp_cache_set(). Adding CDN caching like Cloudflare ensures top-tier performance.

Access the Cache Rules section in Cloudflare

  1. Go to your domain dashboard in Cloudflare
  2. Select the Caching tab → then Cache Rules
  3. Click Create Rule

Create caching condition for Init Live Search REST API

Name the rule something like Cache Init Live Search API, then click Edit expression and enter the condition:

(http.host contains "example.com" and starts_with(http.request.uri.path, "/wp-json/initlise/v1/search") and not http.cookie contains "wordpress_logged_in_")

Note: Replace example.com with your actual domain name.

Other endpoints you can cache

You can create similar Cache Rules for other endpoints, especially slash commands:

  • /wp-json/initlise/v1/recent
  • /wp-json/initlise/v1/related
  • /wp-json/initlise/v1/date
  • /wp-json/initlise/v1/tax
  • /wp-json/initlise/v1/taxonomies

All the endpoints above already support wp_cache_set() in the backend, making them ideal candidates for CDN caching like Cloudflare.

Just duplicate the original rule and change the starts_with(...) part for each new endpoint.

For example, for the /recent endpoint, use this expression:

(http.host contains "example.com" and starts_with(http.request.uri.path, "/wp-json/initlise/v1/recent") and not http.cookie contains "wordpress_logged_in_")

Repeat the pattern for the other endpoints. This is a simple step that greatly speeds up slash command execution—especially for high-traffic sites or those using many taxonomies.

Set cache behavior

After defining the condition, scroll to the Cache settings section and configure as follows:

  • Cache status: On
  • Edge TTL: Choose 300s or 900s depending on how often your content updates
  • Cache key: Click Add setting, then choose Cache Deception Armor to protect against fake query strings

Then click Deploy to finish setup.

Auto purge cache when content updates?

If you want search results to always stay up-to-date (e.g., after publishing new posts), you can use the Cloudflare WordPress plugin to automatically purge cache on content updates.

  1. Log in to the plugin with your Email and Global API Key
  2. Go to the plugin’s Settings
  3. Enable Auto Purge Content On Update

How to check if caching is working

  1. Open your website in incognito mode
  2. Press F12 to open Developer Tools
  3. Go to the Network tab → find requests to /wp-json/initlise/v1/search
  4. Check the cf-cache-status header. If it shows HIT, caching is active.

Conclusion

The Init Live Search plugin is already highly optimized and efficient. But when combined with Cloudflare Cache Rules for its REST API, you’ll get blazing-fast search performance with near-zero server impact.

This is a valuable upgrade for any WordPress site looking to optimize both speed and scalability.

Comments


  • No comments yet.

Web-Based Tools

Press Ctrl + \ on desktop, or swipe left anywhere on mobile.

Login