Support » Plugin: W3 Total Cache » W3 Total Cache: Full Object cache seems to flush when post is updated

  • Bob Hennessey


    I’ve been working with 2 different versions of W3TC (0.9.3 and but am experiencing the same caching issue and I can’t figure out what’s causing it.

    Basically I have W3TC configured to use memcached for object cache on the live servers, and to use disk cached for my dev machine. I have some code that I use to cache various portions of a page:

    global $post;
    			$expire = 60*60*1;
    			$cacheKey= $post->ID."#".$page;
    			$cacheGroup = "single";
    			$output = wp_cache_get( $cacheKey, $cacheGroup );
    			if ( $output != "" ) {
    				// use cached value
    				echo "<!-- use cache: ".$cacheGroup."#".$cacheKey." -->";
    				echo $output;
    			} else {
    				echo "<!-- build cache: ".$cacheGroup."#".$cacheKey." -->";
    HTML HERE...
    				$output =ob_get_flush();
    				// now cache output
    				echo "<!-- save cache: ".$cacheGroup."#".$cacheKey." ".$expire." -->";
    				wp_cache_set( $cacheKey, $output, $cacheGroup, $expire );
    				echo "<!-- done -->";

    This will basically save the display of the body of a page into object cache. 1st request to a page you see the ‘build’ comment, then all following requests until the cache expires you see the ‘use cache’ comment.

    My Problem: I’ve noticed that every time I go into the admin in edit a post and save it (generally in a published state) when I re-request my page I notice it always needed to have the cache rebuilt again. Every page that had been previously cached now needed their cache rebuilt when requested.

    It seems is something is getting trigger on post save that is flushing the object cache. From looking at the plugin settings I don’t see anything.

    I’ve tried shutting off all other plugins, switching themes, but the problem still happens. I would think if this were a problem with W3TC then everyone would be having it.

    Has anyone else had this type of problem?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Bob Hennessey


    From digging further into the latest version of W3TC (0.9.3) I’ve found the following in ObjectCache.php:

    function on_post_change($post_id = 0, $post = null) {
            static $flushed = false;
            if (!$flushed) {
                if (is_null($post))
                    $post = $post_id;
                if ($post_id> 0 && !w3_is_flushable_post($post, 'objectcache', $this->_config)) {
                $flush = w3_instance('W3_CacheFlush');
                $flush->objectcache_flush(); // CLEARS OBJECT CACHE
                $flushed = true;

    So this function is called when a post is edited/modified, so it essentially wipes out the entire object cache every time a new post is published or changed. While this removes the burden on the developer to write flushing specific functions to clear the object cache entries they’ve created it also seems like overkill at the same time.

    I’m starting to look at the older version we have a copy of ( and initially the code looks more selective as to what it flushes based on post_id vs an entire object cache flush.

    Bob Hennessey


    To Frederick Townes: A suggestion to the plugin to make it configurable as to whether to flush the full object cache based on a post being edited and leave it default ‘on’ so its backwards compatible.

    This would allow site owners to write their own code to flush anything they’ve stored in the object cache if appropriate based on a post being updated. In most cases I just set a reasonable cache expiration time so any new changes will eventually show up but the entire cache isn’t cleared.

    Same issue here! huge performance issue for us as we edit post often.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘W3 Total Cache: Full Object cache seems to flush when post is updated’ is closed to new replies.