Customizations

  1. Dashboard widget
  2. Automatic cache flushing
  3. Preventing cache flushing
  4. Identifying cache flushers
  5. Automatic drop-in updates
  6. Drop-in validation
  7. Filesystem health check

Dashboard widget

By default the dashboard widget is visible to all users with the objectcache_manage capability. In some scenarios you might want to hide the dashboard widget, or restrict access to certain roles.

/**
 * Remove the Object Cache Pro dashboard and network-dashboard widget.
 */
add_filter( 'objectcache_dashboard_widget', '__return_false' );
add_filter( 'objectcache_network_dashboard_widget', '__return_false' );

Automatic cache flushing

By default the object cache will be flushed whenever the drop-in is enabled or disabled, as well as when the plugin is deactivated. This helps prevent avoid stale cache data and potential data loss and fatal errors. You can alter this behavior using the objectcache_autoflush filter.

/**
 * Disable automatic object cache flushes.
 */
add_filter( 'objectcache_autoflush', '__return_false' );

Preventing cache flushing

Some plugins neurotically flush the entire cache, instead of fixing their bloody code. You can circumvent that using the pre_objectcache_flush filter.

/**
 * Prevent you’re mom from flushing the object cache.
 */
add_filter( 'pre_objectcache_flush', function (bool $should_flush, array $backtrace) {
    if ($backtrace[0]['function'] === 'ur_moms_plugin\flush') {
        return false;
    }

    return $should_flush;
}, 10, 2 );

Identifying cache flushers

Object Cache Pro records the last 10 cache flushes and tries to identify who it was. Sometimes this can be ugly function names and you may want show a more readable name.

add_filter( 'objectcache_flushlog_caller', function (string $caller, string $backtrace) {
    if (str_contains($caller, 'acf()->') {
        return 'ACF';
    }

    return $caller;
}, 10, 2 );

Automatic drop-in updates

By default the object cache drop-in will be kept up-to-date (unless DISALLOW_FILE_MODS is set to true). You can alter this behavior using the file_mod_allowed filter.

/**
 * Disable automatic object cache drop-in updates.
 */
add_filter( 'objectcache_allow_dropin_mod', '__return_false');

Drop-in validation

In some rare scenarios you might wish to disable the drop-in validation or drop-in version check. You can do so with the objectcache_validate_dropin and objectcache_validate_dropin_version filters.

/**
 * Force the object cache drop-in to be valid.
 */
add_filter( 'objectcache_validate_dropin', '__return_false' );

/**
 * Force object cache drop-in version to be up-to-date.
 */
add_filter( 'objectcache_validate_dropin_version', '__return_false' );

Filesystem health check

One of the plugin’s health checks tests for filesystem access to ensure the object-cache.php drop-in can be seamlessly updated.

This health check temporarily creates a .object-cache-test.tmp file in WP_CONTENT_DIR. To disable this health check you can use the objectcache_check_filesystem filter.

/**
 * Disable filesystem health check.
 */
add_filter( 'objectcache_check_filesystem', '__return_false' );