Purge the page cache
By default, the VIP Platform caches responses from WordPress and Node.js applications by resource URL. Subsequent requests for the same resource URL may receive a previously cached response. Cached content can be purged on demand in the VIP Dashboard, with VIP-CLI, in a WordPress site’s admin tool bar, or with the Cache API.
Cached resource URLs that can be purged include:
- posts and pages
- REST API endpoints
- static assets such as images, CSS, and JS files
VIP Dashboard
Cached URLs of a WordPress or Node.js environment can be purged from the page cache in the Purge Page Cache panel of the VIP Dashboard.
Prerequisite
A user must have at minimum an Org admin role or an App write role for that application.
The Purge Page Cache panel is environment-specific (e.g., Production, Develop). Begin by selecting the environment that is associated with the domain of the URL(s) to be purged. Environments can be selected from the dropdown located at the upper left of the VIP Dashboard application view.
- Navigate to the VIP Dashboard and select the “Cache” panel option at the left.
- Enter one or more URLs sharing the same domain in the “URLs” text field. Multiple URLs must be separated per line by return values.
- Select the “Purge” button to purge the URLs from the page cache.
Up to 4000 URLs can be purged at one time.
VIP-CLI
Purge the page cache for one or more URLs (up to 4,000) sharing the same domain with the VIP-CLI command vip cache purge-url
.
Prerequisites
- VIP-CLI is installed and has been updated to the most current version.
- A user must have at minimum an Org admin role or an App write role for that application.
If multiple URLs are passed in the command, they must be separated by a single space.
vip @<app>.<env> cache purge-url <url> <url>
VIP-CLI command examples
For demonstration purposes, the <app-alias>
value mytestsite
and the <env>
value develop
are used in the VIP-CLI command examples below. Read more about how to target environments in VIP-CLI commands.
In this command example, two URLs hosted on the develop environment of the “mytestsite” application are purged in a single VIP-CLI command:
$ vip @mytestsite.develop cache purge-url https://dev.example.com/page-path/ https://dev.example.com/wp-content/uploads/2020/12/example.png - Purged URL: https://dev.example.com/page-path/ - Purged URL: https://dev.example.com/wp-content/uploads/2020/12/example.png
--from-file
Accepted values: A relative or absolute path to a UTF-8-encoded text file
The --from-file
option extracts a list of URLs from the file existing at the relative or absolute path in the passed value.
Use the --from-file
option to pass a text file containing multiple URLs (separated by newlines) to a vip cache purge-url
command.
In this example command, a list of URLs contained in the multiline contents of a *.txt
file named url-purge-list.txt is passed to the vip cache purge-url
to purge:
vip @mytestsite.develop cache purge-url --from-file=/path/to/url-purge-list.txt
WordPress Admin cache manager
Any logged in user with a role that has the manage_options
capability (usually Administrator
, or Super Admin
) has access to the “Purge Cache For Page” button located in the WordPress Admin tool bar.
The “Purge Cache for Page” option only appears on a site’s front end view when a user is logged in.
Select the “Purge Cache for Page” link to purge the cache for the page being viewed, as well as all file assets referenced by the page (e.g., images, CSS files, JS files).
Cache manager filter
vip_cache_manager_can_purge_cache
returns a boolean whether current user can have access to the “Purge Cache for Page” option based on a capability check. Defaults to current_user_can( 'manage_options' )
.
The following code example will enable access to the “Purge Cache for Page” option for user roles with the edit_others_posts
capability (usually Editor
and greater):
// Allow editors and up to be able to purge a page from cache
add_filter( 'vip_cache_manager_can_purge_cache', function( $can_purge, $user ) {
return current_user_can( 'edit_others_posts' );
}, 10, 2 );
Cache API
Page cache clearing methods using the cache API can be added to a WordPress application’s codebase.