Why My WordPress Scripts Were Wiping the Whole Cache (and How Targeted Purging Fixed It)
Drafted by an AI assistant from my notes and the real changes we made on the sites. I run JustCityGuide, a network of city guides (Rome, Paris, London, New York, Dubai and more) in five languages, plus two sister sites,
Drafted by an AI assistant from my notes and the real changes we made on the sites.
I run JustCityGuide, a network of city guides (Rome, Paris, London, New York, Dubai and more) in five languages, plus two sister sites, JustRoma and JustParigi. Everything runs on WordPress with Elementor, and page caching is handled by WP Rocket with its cache preload (the "warmer") rebuilding pages in the background.
For a while the sites felt slow right after every content update. The cause turned out to be my own maintenance scripts. This is a short write-up of what went wrong and the rules I use now.
The setup
A lot of content on these sites is updated by scripts rather than by hand: internal links between guides, "first time in the city" pages, neighborhood pages. The scripts write directly to the database, so WordPress hooks don't always fire the way they would after a normal save in the editor.
To be safe, each script ended with a full cache purge: the equivalent of WP Rocket's "Clear all cache" (rocket_clean_domain()), sometimes together with regenerating all of Elementor's CSS files.
What actually happened
Every run threw away the cache for every page of the site, in every language, even if the script had touched ten pages. The preload then had to rebuild thousands of URLs from scratch. Until it caught up, real visitors and Googlebot were hitting uncached, slow pages.
With several scripts running on different days, the cache was almost never fully warm.
The rules I follow now
1. Normal edits: let WP Rocket do its job. When a page, guide, intro or layout is changed through the normal WordPress or Elementor save, WP Rocket already purges the affected page and its related URLs. No manual purge needed.
2. Scripts purge only what they touch. If a script writes data directly, it collects the IDs of the posts it changed and clears only those, plus their obvious dependencies (the parent guide, the category or listing pages that show them). WP Rocket exposes functions for this, such as rocket_clean_post( $post_id ), so there's no reason to clear the whole domain.
3. No global purge for ordinary changes. rocket_clean_domain(), "Clear all cache" and a global regeneration of Elementor files are reserved for real global changes: a theme update, a header change on every page, a plugin update that changes markup.
4. When a full purge is necessary, do one site at a time. Purge one site, check the front end, check the purge log, and wait for the preload to pick up again before moving to the next one. Note that updating WP Rocket itself can clear the cache of the site being updated, so plan updates the same way.
5. Old scripts get archived, not "fixed later". The scripts that ended with a full purge were archived, so nobody (human or AI) runs them again by accident.
The takeaway
A full cache purge feels like the safe option, because you know nothing stale is left. On a multilingual site with thousands of URLs it's the opposite: it guarantees slow pages for a while after every change. Purging narrowly is a little more work in the script, and much less work for your server and your visitors.
If you're curious about the sites themselves, the ticket comparator is the part I'm happiest with: it compares the same attraction ticket across several booking platforms.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.