Clearing a Specific URL via PHP
Table of Contents
Sometimes it is nice to take more control over the way cache files are cleared. Using PHP functions provided by the Comet Cache plugin is one of the most powerful ways to do that. There are a number of API Functions provided by the Comet 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 Comet Cache plugin has been loaded and is available for use within your code.
Clearing a Specific URL
The above will clear this specific URL from the cache.
Clearing Multiple URLs Matching a Pattern
comet_cache::clearUrl() function also supports Watered-Down Regex, making it easy to clear multiple URLs matching a pattern.
Clears all URLs that begin with
Clearing a Specific WordPress Post/Page by ID
The above will clear this specific Post ID from the cache.
Clearing a Specific User by User ID
Whenever user-specific caching is enabled in your Comet Cache configuration, each user can be associated with a version of the cache that is served only to that user while they are logged-in. This makes it possible for you to clear the entire cache for that specific user without impacting other visitors to the site, or other users who are also logged into the site.
The above will clear this specific User ID from the cache.
Clearing the Current User ID
The above will clear the current User ID from the cache; i.e., the user who is currently logged into the site whenever this API Function is called upon.