W3 Total Cache
W3 Total Cache - Cache auto pruning when a new comment is added (2 posts)

  1. Pennywise83
    Posted 3 years ago #

    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?


  2. laurionb
    Posted 3 years ago #

    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).

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • W3 Total Cache
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic