WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
[resolved] 'site-transient' object cache in wp-admin (4 posts)

  1. sboisvert
    Member
    Posted 3 years ago #

    The "Don't cache WordPress Admin" feature on /wp-admin/admin.php?page=w3tc_objectcache should still set the cache for 'site-transient' or at the very least should not use the object cache to pull its objects from it because what happens is that you log in the backend. Its been a while since the last time so you trip the version check, the plugin check the theme check and etc. Those values are or were cached somehow, and never get updated because of the wp-admin restriction.

    Not sure how to best resolve the problem

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. sboisvert
    Member
    Posted 3 years ago #

    We fixed it like such:
    I'm sure there is a better, more long term solution than to hack some actions and filters, but in the mean time if anyone wants a cheap and chearful answer:

    // Enable caching transient options
    /**
    * Turn on caching if it is turned off
    *
    */
    function liberal_turn_on_admin_cache($value) {
        global $wp_object_cache;
    
        //save old value to check if we need to restore it later; save it at first visit only
        if( !$wp_object_cache->_caching_saved && !$wp_object_cache->_caching ) {
            $wp_object_cache->_caching_saved = true;
            $wp_object_cache->_caching = true;
        }
    
        //Do nothing with the input value
        return $value;
    }
    
    /**
    * Turn off caching if it was turned on before
    *
    */
    function liberal_turn_off_admin_cache($value=false) {
        global $wp_object_cache;
    
        //restore value if it was saved
        if( $wp_object_cache->_caching_saved && $wp_object_cache->_caching ) {
            $wp_object_cache->_caching_saved = false;
            $wp_object_cache->_caching = false;
        }
    
        //Do nothing with the input value
        return $value;
    }
    
    /**
    * Init filters for caching transient options
    *
    */
    function liberal_enable_caching_transient_options() {
        $transient_options = array(
            'update_core',
            'update_plugins',
            'update_themes',
            'theme_roots',
        );
        foreach($transient_options as $option_name) {
            add_filter( 'pre_set_site_transient_'.$option_name, 'liberal_turn_on_admin_cache', 10, 1 );
            add_action( 'set_site_transient_'.$option_name , 'liberal_turn_off_admin_cache', 10, 0 );
            add_filter( 'pre_site_transient_'.$option_name, 'liberal_turn_on_admin_cache', 10, 1 );
            add_filter( 'site_transient_'.$option_name , 'liberal_turn_off_admin_cache', 10, 1 );
        }
    }
    if( defined('WP_ADMIN') ) liberal_enable_caching_transient_options();
    // End Enable caching transient options
  3. markusrichert
    Member
    Posted 3 years ago #

    Nice code, thanks a lot for that.
    But where exactly has this to go? All locations I tried, didn't work. :-(

  4. sboisvert
    Member
    Posted 3 years ago #

    in a file in mu-plugins

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic