Customize page cache behavior
Select behavior of the VIP page cache can be controlled using VIP’s Cache API. Some of the Cache API controls are provided by VIP MU plugins and must be implemented by a WordPress application. Other controls are generic HTTP concepts that can be used by both WordPress and Node.js applications.
Custom NGINX rules cannot be added to modify the behavior of the page cache for a WordPress or Node.js application.
Note
When purging a URL from the page cache, all variants of the URL’s GET parameters will also be purged. Purging a post with slug hello-world will also purge other cached variants such as /hello-world/?a=1&b=1 as well as /hello-world/?b=1&a=1. It is not possible to purge a specific variant of a URL without purging all if its other variants.
Filter URLs to be cleared when a post is changed
When a post is published, unpublished, or if a published post is modified, a default set of URLs are assembled to be purged. WordPress applications can use the wpcom_vip_cache_purge_{$post->post_type}_post_urls filter to specify additional URLs that should be purged.
A code example demonstrating use of the filter:
add_filter( 'wpcom_vip_cache_purge_post_post_urls', 'my_cache_purge_post_urls', 10, 2 );
/**
* Hooks the wpcom_vip_cache_purge_post_post_urls filter to
* also clear a custom JSON endpoint for the post URL.
*
* This targets posts of post type "post" only.
*
* @param array urls An array of URLs to be purged
* @param int post_id The ID of the post for which we're purging URLs
* @return array An array of URLs to be purged
*/
function my_cache_purge_post_urls( $urls, $post_id ) {
$post = get_post( $post_id );
if ( empty( $post ) ) {
return $urls;
}
// Also purge the JSON format for the posts
$urls[] = get_permalink( $post_id ) . '/json/';
return $urls;
}Note
The wpcom_vip_cache_purge_{$post->post_type}_post_urls filter can also be used to purge URLs belonging to a related Node.js application, such as a decoupled frontend. However, if a post’s permalink already points to the decoupled frontend, it will be purged automatically and there is no need to use this filter.
Filter URLs to be cleared when a term is changed
Whenever a term is created, changed, or deleted, a default set of URLs is assembled to be purged. WordPress applications can use the wpcom_vip_cache_purge_{$taxonomy_name}_term_urls filter to specify additional URLs that should be purged.
A code example demonstrating use of the filter:
add_filter( 'wpcom_vip_cache_purge_category_term_urls', 'my_cache_purge_term_urls', 10, 2 );
/**
* Hooks the wpcom_vip_cache_purge_category_term_urls filter to
* also clear a custom JSON endpoint for the term archive
*
* @param array urls An array of URLs to be purged
* @param int term_id The ID of the term for which we're purging URLs
* @return array An array of URLs to be purged
*/
function my_cache_purge_term_urls( $urls, $term_id ) {
$term = get_term( $term_id );
if ( is_wp_error( $term ) || empty( $term ) ) {
return false;
}
$term_link = get_term_link( $term, $taxonomy_name );
if ( is_wp_error( $term_link ) ) {
return false;
}
if ( $term_link && is_string( $term_link ) ) {
$this->purge_urls[] = $term_link . '/json/';
}
return $urls;
}Note
The wpcom_vip_cache_purge_{$taxonomy_name}_term_urls filter can also be used to purge URLs belonging to a related Node.js application, such as a decoupled frontend. However, if a term’s permalink already points to the decoupled frontend, it will be purged automatically and there is no need to use this filter.
Clear caches for a post, term, or a specific URL
In WordPress applications, functions are available to manually clear specific cache objects.
wpcom_vip_purge_edge_cache_for_url( $url ): Purge the page cache for a specific URL, including URLs for media files, CSS, JS, or a URL belonging to a related Node.js application, such as a decoupled frontend.wpcom_vip_purge_edge_cache_for_post( $post ): Purge URLs related to a post from the page cache. The purged URLs can be controlled using thewpcom_vip_cache_purge_{$post->post_type}_post_urlsfilter.wpcom_vip_purge_edge_cache_for_term( $term ): Purge URLs related to a term from the page cache. The purged URLs can be controlled using thewpcom_vip_cache_purge_{$taxonomy_name}_term_urlsfilter.
Purging can take up to 10 seconds to complete across all VIP edge cache servers, though the average is around 70ms. In one analysis of 10 million requests, only 0.00252% of purge requests took longer than 200ms.
Set individual users or requests to bypass the cache
Use the vip-go-cb cookie on WordPress or Node.js applications to allow selected users to bypass the page cache. This method allows responses to be personalized, and to never be cached and served to other users.
Methods for bypassing the cache can be useful for sites with a paywall or as part of A/B testing functionality. However it should be used with caution, as requests made by users that bypass the cache will always be processed by the origin servers.
- Requests with the
vip-go-cbcookie set to a value of1(it must be a value of1) will alwaysBYPASSthe page cache. As a result, these requests will never be served a cached response, and the response to these requests will never be cached to be served to others. - On WordPress applications, requests from logged-in users will always
BYPASSthe cache; setting this cookie for logged-in WordPress users is not necessary. If users are logging in using a different mechanism, set thevip-go-cbcookie in addition to any other cookies or local storage data for a third-party login system. Be sure that these users will not have responses cached or see cached responses.
The Vary HTTP response header
On the VIP Platform, the Vary HTTP response header is respected for these values:
originRSCx-vip-go-segmentationx-vip-go-authx-country-codex-continentx-regionx-metro-codex-cityx-postal-code
Geolocation on VIP
The Vary IP geolocation response headers can be utilized by WordPress and Node.js applications to deliver variations of cached content based on an end user’s global location.
For WordPress sites, country-based IP geolocation can also be managed with the VIP Go Geo Uniques plugin. The plugin is specifically designed to work with the VIP Platform’s page cache, but is currently limited to only respect the vary: x-country-code header.
Vary cached content by User-Agent class
For all requests (except those by logged-in WordPress users), the x-mobile-class HTTP request header is populated with 1 of 4 values that correspond to VIP’s classification of the request’s User-Agent.
x-mobile-class response | Response description |
|---|---|
desktop | This device is likely a desktop or it did not match any of the known user agents we know about. |
tablet | This device is likely a tablet (Android / iOS) |
smart | This device is likely a smart phone |
dumb | This device is likely a “dumb” phone |
x-mobile-class HTTP response header and their descriptionsBy inspecting the value of the x-mobile-class request header, an application can conditionally alter its response. The result will be cached correctly in its own page cache “bucket”.
Last updated: September 24, 2025