Skip to content

Clearing a Specific URL via PHP

Darko Gjorgjijoski edited this page Sep 6, 2020 · 5 revisions

Sometimes it is nice to take more control over the way cache files are cleared. Using PHP functions provided by the Rapid Cache plugin is one of the most powerful ways to do that. There are a number of API Functions provided by the Rapid Cache plugin. I will mention a few of them below and provide examples of their use.

Note: Before you integrate any of the functions shown below, it's important to remember that much of WordPress is driven by hooks and filters. For that reason, before you call any of these functions, please be sure that the init hook has been fired first; i.e., that the Rapid Cache plugin has been loaded and is available for use within your code.


Clearing a Specific URL

<?php
rapidcache_clear_url_cache('http://example.com/path/to/page/');

The above will clear this specific URL from the cache.

Clearing Multiple URLs Matching a Pattern

The rapidcache_clear_url_cache function also supports Watered-Down Regex Syntax, making it easy to clear multiple URLs matching a pattern.

<?php
rapidcache_clear_url_cache('http://example.com/post/**');

Clears all URLs that begin with http://example.com/post/

Clearing a Specific WordPress Post/Page by ID

<?php
rapidcache_clear_post_cache(123);

The above will clear this specific Post ID from the cache.

Clone this wiki locally