WordPress.org

Support

Support » Plugins and Hacks » W3 Total Cache » W3 Total Cache – Cache auto pruning when a new comment is added

W3 Total Cache – Cache auto pruning when a new comment is added

  • Hi,
    I’m using W3 Total Cache with object cache enabled through memcache.

    I wrote a custom plugin that show the latest X comments of the blog.
    I want to cache the results in a transient cache object that expire every X minutes.

    This is the code:

    $key = 'recent_comments'.md5($sql);
        $comments = wp_cache_get($key,$group);
    
        if ( empty( $comments ) ) {
            $comments = $wpdb->get_results($sql);
            wp_cache_set( $key, $comments, $gruop, RECENT_COMMENTS_TIME );
        }
    	foreach ($comments as $key => $comment) {

    The caching does work, but when someone adds a new comment the cache object is erased, and I don’t know why.

    Anyone can help me?

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

Viewing 1 replies (of 1 total)
  • laurionb

    @laurionb

    When a new comment is added W3TC always empties both the object and db caches. This has the effect of wiping out your cached comments. If you really want to keep the comments cached separately you will need to handle the caching yourself (e.g., by putting the comments in memcached, assuming W3TC isn’t using memcached).

Viewing 1 replies (of 1 total)
  • The topic ‘W3 Total Cache – Cache auto pruning when a new comment is added’ is closed to new replies.
Skip to toolbar