A Persistent Object Cache improves page load times by reducing repeated database queries from the application or web server. Pressidium provides an efficient Object Cache out of the box, fully integrated with its multi-adaptive cache engine and backed by Redis. While persistent object caching can deliver significant performance gains, in some cases it may conflict with certain plugins or themes.

To debug potential issues, you can temporarily disable persistent object caching by setting the WP_REDIS_DISABLED constant to true in the wp-config.php configuration file. This will prevent the Pressidium object cache drop-in from using Redis to manage object cache entries.

define('WP_REDIS_DISABLED', true);

The following simplified PHP code shows how to conditionally disable the object cache based on the request URL and the HTTP Referer (when doing AJAX requests). The code must be placed in wp-config.php or in a file included from it (via an include , require or similar directive), since it has to execute early in the WordPress bootstrap process.

// wp-config.php
...
if ( file_exists( __DIR__ . "/conditionally-disable-object-cache.php" ) ){    
    require_once __DIR__ . "/conditionally-disable-object-cache.php"; 
} 

/* That's all, stop editing! Happy publishing. */
<?php

// FILE: conditionally-disable-object-cache.php

// Update this array with the URIs that should 
// not use persistent object caching
$pressidium_object_cache_excluded_uris = array(
    '/uri-to-exclude',
    '/another-uri-to-exclude',
);

function pressidium_should_disable_object_cache() {
    global $pressidium_object_cache_excluded_uris;

    if ( ( ( defined( 'WP_CLI' ) && WP_CLI ) 
        || php_sapi_name() === 'cli' ) 
        || ! isset( $_SERVER['REQUEST_URI'] ) ) {
        return false;
    }

    $request_path = rtrim( 
        parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ), 
        '/' 
    );
    $request_path = empty( $request_path ) ? '/' : $request_path;

    $excluded_uris = array();
    foreach ( $pressidium_object_cache_excluded_uris as $uri ) {
        $excluded_uris[] = '/' . trim( $uri, '/' );
    }

    if ( in_array( $request_path, $excluded_uris ) ) {
        return true;
    }

    if ( defined( 'DOING_AJAX' ) && DOING_AJAX
        && isset( $_SERVER['HTTP_REFERER'] )
        && in_array( 
              rtrim( $_SERVER['HTTP_REFERER'], '/' ), 
              $excluded_uris 
    ) ) {
        return true;
    }

    return false;
}

if ( pressidium_should_disable_object_cache() 
     && ! defined( 'WP_REDIS_DISABLED' ) ) {
    define( 'WP_REDIS_DISABLED', true );
}

Need help?

If you are not sure whether disabling persistent object cache is appropriate for your site or plugin, contact our Support team before adding custom code.

Open a support request

Where to go next