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:

  1. Connect to your server using SFTP, SSH, or the RunCloud File Manager.
  2. Navigate to wp-content > mu-plugins. If the mu-plugins directory does not exist, create it.
  3. Create a new PHP file, such as runcache-custom.php.
  4. Open the file and write your custom hook callback.
  5. 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 NameArgumentsDescription
runcache_cache_providersarray $providersMaps page cache provider keys to provider objects. Bundled providers register here. Values must implement RunCache\Integrations\Interfaces\CacheProvider.
runcache_cache_settingsarray $settingsModifies 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_savearray $settings, array $previous_settingsModifies page cache settings right before RunCache writes them to the database.
runcache_rules_settingsarray $settingsModifies exclusion rules (such as URLs, cookies, query parameters, user agents, and IP addresses).
runcache_object_cache_settingsarray $settingsModifies settings for Object Cache. Controls options found under “Object Cache”.
runcache_object_cache_providersarray $providersMaps object cache provider keys to provider objects.
runcache_cdn_settingsarray $settingsModifies Assets CDN settings. Controls options found under “Assets CDN”.
runcache_cdn_providersarray $providersMaps CDN provider keys to provider objects.
runcache_validated_settingsarray $settingsFilters the settings array immediately after the internal validator finishes sanitizing values.

Edge Cache and Purge Filters

Filter NameArgumentsDescription
runcache_cloudflare_purge_chunk_sizeint $chunk_size (default: 30)Sets how many URLs RunCache includes in a single Cloudflare purge API request.
runcache_cloudflare_apo_purge_chunk_sizeint $chunk_size (default: 30)Sets the purge request chunk size specifically for the Cloudflare APO integration.

Cache Statistics Filters

Filter NameArgumentsDescription
runcache_stats_providernull $statsOverrides 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 NameArguments PassedTriggers When
runcache_cache_settings_savedarray $settingsPage cache settings save successfully. RunCache uses this to rewrite configuration files and refresh stats.
runcache_rules_updatedarray $validatedCache exclusion rules save successfully.
runcache_purger_updatedarray $validatedPurger settings save successfully.
runcache_preloader_updatedarray $validatedPreloader schedule and settings save successfully.
runcache_object_cache_settings_savedarray $settingsObject cache settings save successfully.
runcache_cdn_settings_savedarray $settings, array $existing_settingsCDN settings save successfully.
runcache_edge_settings_savedarray $settings, mixed $previous_providerEdge caching settings (Cloudflare or Cloudflare APO) save successfully.
runcache_validator_initializedValidator $validatorThe 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 NameArguments PassedTriggers When
runcache_after_purge_allNoneA complete cache purge finishes across the entire site.
runcache_after_purge_networkNoneA network-wide purge finishes across a WordPress Multisite network.
runcache_after_purge_expiredNoneThe routine sweep of expired cached files completes.
runcache_after_purge_postint $post_id, array $urlsRunCache purges a specific post and its associated archive URLs.
runcache_after_purge_urlstring $urlRunCache purges an individual URL.
runcache_after_preload_completearray $queueThe 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 NameArguments Passed
runcache_nginx_cache_enabled / runcache_nginx_cache_disabledNginx $provider
runcache_fastcgi_cache_enabled / runcache_fastcgi_cache_disabledFastCGI $provider
runcache_apache_cache_enabled / runcache_apache_cache_disabledApache $provider
runcache_redis_cache_enabled / runcache_redis_cache_disabledRedis $provider

To continue customizing your caching infrastructure, review our related technical guides: