WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. Pennywise83
    Member
    Posted 1 year ago #

    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/

  2. laurionb
    Member
    Posted 1 year 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

About this Topic