Trouble with Transient API when W3TC is activated [closed]

I was having this same issue and was able to correct it by expanding on Andy’s solution, however I only needed to force on value in particular to not use W3TC’s object cache. I tried using APC, Memcached as well as Disk for the cache with the same results. Caching certainly helps performance, and the code I was having an issue with is not my own (a plugin) so modifying it inline was not an option…. enter filters/actions. I was able to get it working by using the following, replacing TRANSIENT_KEY with the key you want to disable caching for:

global $_wp_using_ext_object_cache_prev;
function disable_linked_in_cached($value=null){
    global $_wp_using_ext_object_cache;
    $_wp_using_ext_object_cache_prev = $_wp_using_ext_object_cache;
    $_wp_using_ext_object_cache = false;
    return $value;
}
add_filter( 'pre_set_transient_TRANSIENT_KEY', 'disable_linked_in_cached' );
add_filter( 'pre_transient_TRANSIENT_KEY', 'disable_linked_in_cached' );
add_action( 'delete_transient_TRANSIENT_KEY', 'disable_linked_in_cached' );

function enable_linked_in_cached($value=null){
    global $_wp_using_ext_object_cache;
    $_wp_using_ext_object_cache = $_wp_using_ext_object_cache_prev;
    return $value;
}
add_action( 'set_transient_TRANSIENT_KEY', 'disable_linked_in_cached' );
add_filter( 'transient_TRANSIENT_KEY', 'enable_linked_in_cached' );
add_action( 'deleted_transient_TRANSIENT_KEY', 'disable_linked_in_cached' );

Leave a Comment