PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.4.1
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.4.1
1.4.1 1.4.0 1.3.7 1.3.6 1.3.5 1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 All 35 releases
← All changes | includes/class-host-page-caches.php +44 -5 1.3.7 → 1.4.1 View file →
@@ -53,14 +53,15 @@
53 53 * one level up, by `Server_Caches::forward()`, from the `intent` and `scope`
54 54 * on the purge-event contract — which is also where the reasoning for standing
55 55 * down on a content purge is written. Nothing here listens to a hook.
56 56 *
57 - * Purge-ALL only. Nginx Helper's per-URL entry point is
57 + * Two calls: purge_nginx_helper() clears the whole zone through the action
58 + * above, and purge_nginx_helper_urls() clears named pages through
58 59 * `$GLOBALS['nginx_purger']->purge_url()`, a method on its purger object
59 - * rather than an action, and it calls `is_page()`/`is_single()` internally —
60 - * which emits `_doing_it_wrong` outside a main query, so WP-CLI, cron and REST
61 - * purges would warn. The contract already carries the exact `urls`, so
62 - * per-URL forwarding is a follow-up rather than a redesign.
60 + * rather than an action. That method checks `is_page()`/`is_single()` before
61 + * purging an AMP copy; both only warn when the global `$wp_query` does not
62 + * exist, and `wp-settings.php` creates it for every request, so WP-CLI, cron
63 + * and REST purges are quiet.
63 64 *
64 65 * **Multisite:** nginx keys one cache zone per *install*, not per subsite, so
65 66 * a purge here clears every site on the network at the nginx layer. That is
66 67 * accepted rather than worked around — a cold cache costs one slow request
@@ -127,8 +128,46 @@
127 128 */
128 129 return false;
129 130 }
130 131
132 + return true;
133 + }
134 +
135 + /**
136 + * Purge named pages from the nginx FastCGI cache through Nginx Helper.
137 + *
138 + * Its purger's `purge_url()` is the same call Nginx Helper makes for its
139 + * own post purges. Feeds are not added (`$feed = false`): xSpeed names the
140 + * feeds it means. If the purger cannot take a URL, the whole zone goes
141 + * instead, because a page left stale is worse than a cold cache. The
142 + * same happens when the calls run past `$seconds`: with the `get_request`
143 + * method each one is a blocking HTTP request, and a slow purge endpoint
144 + * would otherwise hold the request for the whole list.
145 + *
146 + * @param string[] $urls Absolute URLs on this site.
147 + * @param float $seconds Time allowed for the per-URL calls; 0 for no limit.
148 + */
149 + public static function purge_nginx_helper_urls( array $urls, float $seconds = 0.0 ): bool {
150 + if ( array() === $urls || ! self::nginx_helper_is_fastcgi() ) {
151 + return false;
152 + }
153 + $purger = $GLOBALS['nginx_purger'] ?? null;
154 + if ( ! is_object( $purger ) || ! method_exists( $purger, 'purge_url' ) ) {
155 + return self::purge_nginx_helper();
156 + }
157 + $started = microtime( true );
158 + $left = count( $urls );
159 + try {
160 + foreach ( $urls as $url ) {
161 + $purger->purge_url( (string) $url, false );
162 + --$left;
163 + if ( $left > 0 && $seconds > 0 && microtime( true ) - $started > $seconds ) {
164 + return self::purge_nginx_helper();
165 + }
166 + }
167 + } catch ( \Throwable $e ) {
168 + return self::purge_nginx_helper();
169 + }
131 170 return true;
132 171 }
133 172
134 173 /**