- Serve cache via template_redirect so feeds/404/REST are excluded and query conditionals work - Bypass cache on query strings; key files by md5(host+path) to avoid collisions and support multisite - Write wp-content/wp-recache-cache.php drop-in server and set WP_CACHE in wp-config.php so advanced-cache.php actually runs - Only remove advanced-cache.php on deactivation when it is ours - Respect DONOTCACHEPAGE, non-200 responses; bots read but never warm cache - Fix comment purge (comment_post_ID) and heartbeat purge ($data arg) - Fix exclude URLs textarea parsing; purge all when exclusions change - Enqueue admin purge script on every admin-bar page, not just settings - Sync tests, add TESTING.md manual test guide
3.2 KiB
3.2 KiB
Testing WP Recache (manual)
Environment: Docker (docker-compose up -d), or any WP ≥ 5.8 + PHP ≥ 7.4 install with the plugin symlinked into wp-content/plugins/.
Activation
- Activate the plugin.
- Check
wp-config.phpcontainsdefine('WP_CACHE', true); // Added by WP Recache. - Check these files exist:
wp-content/advanced-cache.phpwp-content/wp-recache-cache.phpwp-content/cache/wp-recache/.htaccess+index.php
Core cache (issue #1 stories 1, 11, 12)
- Anonymous visit (incognito) to a page twice:
- 1st: response header
X-WP-Recache: MISS, filemd5(host + path) . '.html'appears inwp-content/cache/wp-recache/. - 2nd:
X-WP-Recache: HIT(via WP) orX-WP-Recache-Dropin: 1(served before WP loaded).
- 1st: response header
- Same URL with
?utm_source=test: always MISS, no new cache file (query strings bypass). - Define
DONOTCACHEPAGEon a page (e.g. in a must-use plugin): page never cached. - Logged-in visit: no
X-WP-Recacheheaders, nothing cached (logged-in cookie also bypasses the drop-in).
Exclusions (stories 4–6)
- Settings → Cache → Exclude URLs: add
/about, save, visit/abouttwice → never cached. - Default exclusions:
/cart,/checkout,/my-accountnever cached. - Feeds (
/feed/) and 404 pages: noX-WP-RecacheMISS header, no cache file.
Purge (stories 2, 3)
- Edit a published post → its cache file and the homepage file are deleted.
- Add a comment to a post → that post's cache file is deleted (not the comment ID's).
- Admin bar → WP Recache → Purge All Cache (works on every admin page AND on the front-end admin bar, not just the settings page) → cache dir emptied.
- Settings → Advanced → Purge All Cache button → same result.
- Heartbeat purge:
wp.heartbeat.send('wp_recache_purge', 1)in browser console on an admin page → next heartbeat tick purges all (check responsewp_recache_purged).
Mobile (story 7)
- Enable "Separate Mobile Cache", visit once with a mobile UA (
curl -A "iPhone"), once desktop → two files:*-mobile.html,*-desktop.html. - With mobile cache ON, the drop-in does not serve (falls through to WP path) — expected.
Stats (story 9)
- Settings → Cache → Cache Statistics shows file count and size matching
wp-content/cache/wp-recache/.
Multisite (story 10)
- On a network: same path on two sites produces two different files (host+path in key). Purge on one site must not touch the other.
Deactivation / uninstall
- Deactivate:
advanced-cache.php,wp-recache-cache.phpremoved,WP_CACHEmarker line removed fromwp-config.php. - If another plugin's
advanced-cache.phpexists (no "WP Recache" marker), deactivation must NOT delete it. - Uninstall: options deleted,
wp-content/cache/wp-recache/removed.
Automated
composer test(PHPUnit, needs WP test suite via docker-compose).composer phpstan,composer lint.
Known ceilings
- Drop-in ignores
cache_durationTTL (no WP available to read the option); freshness relies on purge-on-update. Files are never served stale for edited content, only for TTL-based expiry. - Preload toggle (story 8) has no crawler implementation yet.
- Purge on publish clears only the post + homepage; archives/taxonomy pages expire via TTL.