RunCache is built to provide high-speed caching for your WordPress web applications right out of the box. If you are a developer or site builder, you can also customize how RunCache behaves by using custom code.
Since RunCache uses standard WordPress functions like apply_filters() and do_action(), you can interact with them using standard WordPress add_filter() and add_action() functions.
When to Register Your Hooks
All RunCache modules initialize on the standard plugins_loaded WordPress hook.
If your code modifies settings before the plugin reads them, you must register your callbacks before plugins_loaded completes. The most reliable way to do this is inside a Must-Use plugin (located in wp-content > mu-plugins) or at the top of your active theme’s functions.php file.
Important Timing Note for Exclusion Rules
The runcache_rules_settings filter has a unique timing requirement. The early cache drop-in file reads exclusion rules before WordPress fully loads. Because of this, standard callbacks will not intercept the early check. The drop-in file reads a generated configuration file instead. If you need to bypass page caching dynamically in your custom code, follow our guide on how to exclude a page from cache using code.
How to Add a RunCache Hook
To add a custom filter or action to your site, follow these steps:
- Connect to your server using SFTP, SSH, or the RunCloud File Manager.
- Navigate to wp-content > mu-plugins. If the mu-plugins directory does not exist, create it.
- Create a new PHP file, such as
runcache-custom.php. - Open the file and write your custom hook callback.
- Save the file and verify your site functionality in your browser.
For example, you can use the following code to email the administrator whenever Redis caching is turned off:
add_action( 'runcache_redis_cache_disabled', function( $provider ) {
$admin = get_option( 'admin_email' );
wp_mail( $admin, '[Alert] Redis Disabled', 'Redis cache was turned off. Database load may increase.' );
} );In the code snippet above, the provider status actions are triggered whenever server-level caching layers are toggled. These are useful for sending instant alerts or audit logs when critical caches such as Redis or NGINX are disabled in production, helping prevent unexpected spikes in database performance.
RunCache Filters
Filters let you intercept and modify data before RunCache stores it, reads it, or sends it to the server.
Settings and Provider Filters
| Filter Name | Arguments | Description |
|---|---|---|
runcache_cache_providers | array $providers | Maps page cache provider keys to provider objects. Bundled providers register here. Values must implement RunCache\Integrations\Interfaces\CacheProvider. |
runcache_cache_settings | array $settings | Modifies full-page cache settings after server defaults merge. Runs every time settings are read. Controls the options seen under “Full Page Cache”. |
runcache_cache_settings_before_save | array $settings, array $previous_settings | Modifies page cache settings right before RunCache writes them to the database. |
runcache_rules_settings | array $settings | Modifies exclusion rules (such as URLs, cookies, query parameters, user agents, and IP addresses). |
runcache_object_cache_settings | array $settings | Modifies settings for Object Cache. Controls options found under “Object Cache”. |
runcache_object_cache_providers | array $providers | Maps object cache provider keys to provider objects. |
runcache_cdn_settings | array $settings | Modifies Assets CDN settings. Controls options found under “Assets CDN”. |
runcache_cdn_providers | array $providers | Maps CDN provider keys to provider objects. |
runcache_validated_settings | array $settings | Filters the settings array immediately after the internal validator finishes sanitizing values. |
Edge Cache and Purge Filters
| Filter Name | Arguments | Description |
|---|---|---|
runcache_cloudflare_purge_chunk_size | int $chunk_size (default: 30) | Sets how many URLs RunCache includes in a single Cloudflare purge API request. |
runcache_cloudflare_apo_purge_chunk_size | int $chunk_size (default: 30) | Sets the purge request chunk size specifically for the Cloudflare APO integration. |
Cache Statistics Filters
| Filter Name | Arguments | Description |
|---|---|---|
runcache_stats_provider | null $stats | Overrides the statistics array that RunCache collects. The return value is stored in the runcache_stats transient for 60 seconds. Read our guide on replacing the statistics with your own numbers for code samples. |
Standalone Utility Filters
RunCache registers handlers for two filters that you can trigger manually from your own code:
apply_filters( 'runcache_get_stats', $value ): Retrieves the current cache statistics array.apply_filters( 'runcache_purge_and_preload', $value ): Clears the cache completely and immediately triggers a background preload sweep. Note that clicking the Purge cache and Preload cache buttons in the WordPress admin uses an AJAX request rather than this filter.
RunCache Actions
Actions allow your custom code to run tasks when specific cache events happen.
Settings Lifecycle Actions
These actions run whenever an administrator updates configuration tabs in the RunCache dashboard.
| Action Name | Arguments Passed | Triggers When |
|---|---|---|
runcache_cache_settings_saved | array $settings | Page cache settings save successfully. RunCache uses this to rewrite configuration files and refresh stats. |
runcache_rules_updated | array $validated | Cache exclusion rules save successfully. |
runcache_purger_updated | array $validated | Purger settings save successfully. |
runcache_preloader_updated | array $validated | Preloader schedule and settings save successfully. |
runcache_object_cache_settings_saved | array $settings | Object cache settings save successfully. |
runcache_cdn_settings_saved | array $settings, array $existing_settings | CDN settings save successfully. |
runcache_edge_settings_saved | array $settings, mixed $previous_provider | Edge caching settings (Cloudflare or Cloudflare APO) save successfully. |
runcache_validator_initialized | Validator $validator | The settings validator completes its initial setup. |
Purge and Preload Actions
Use these actions to trigger third-party services, notify uptime monitors, or write log messages when cache flushes occur. Each of these actions also clears the cached dashboard metrics.
| Action Name | Arguments Passed | Triggers When |
|---|---|---|
runcache_after_purge_all | None | A complete cache purge finishes across the entire site. |
runcache_after_purge_network | None | A network-wide purge finishes across a WordPress Multisite network. |
runcache_after_purge_expired | None | The routine sweep of expired cached files completes. |
runcache_after_purge_post | int $post_id, array $urls | RunCache purges a specific post and its associated archive URLs. |
runcache_after_purge_url | string $url | RunCache purges an individual URL. |
runcache_after_preload_complete | array $queue | The background cache warming preloader finishes its queue. |
Provider Status Actions
These actions run when an administrator toggles a server-level cache provider on or off.
| Action Name | Arguments Passed |
|---|---|
runcache_nginx_cache_enabled / runcache_nginx_cache_disabled | Nginx $provider |
runcache_fastcgi_cache_enabled / runcache_fastcgi_cache_disabled | FastCGI $provider |
runcache_apache_cache_enabled / runcache_apache_cache_disabled | Apache $provider |
runcache_redis_cache_enabled / runcache_redis_cache_disabled | Redis $provider |
Related Developer Guides
To continue customizing your caching infrastructure, review our related technical guides:
- Learn about the WordPress constants you can set in wp-config.php to control cache paths and debugging.
- Learn how to read the plugin logs to troubleshoot failures in WordPress.