WordPress.org

Support

Support » Plugins and Hacks » W3 Total Cache » [Plugin: W3 Total Cache] Automatically empty cache when updating posts/pages

[Plugin: W3 Total Cache] Automatically empty cache when updating posts/pages

  • Hiya,

    I’ve been fiddling with this plugin for a while and am very happy with how its working for the most part. I have it set up somewhat like Movable Type in that all pages are fully cached and when one page is viewed it automatically caches the rest using the site map. This works really nicely as it ensures that the vast majority of people always encounter a cached page.

    The only hole is that if I update or add a post or page (or do anything that affects menus, etc) I’ve got a load of cached pages that won’t show my changes until the cache next expires after 3600 seconds or whatever. So my sidebar which lists the latest posts won’t include the latest post on most pages, for example.

    Is there any way to make it so W3 Total Cache empties its caches whenever things are saved in WordPress? So for example if a page or post is modified, a comment is left, etc it clears everything. Even better if there could be some kind of throttle (eg: if 20 people comment within a minute, it’ll wait a minimum of a minute before trying to clear and subsequently repopulate the cache except for that one page).

    If nothing like this exists it’d be a nice feature to investigate I think. 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • Yup this is on my wishlist too… specifying when to clear the cache – on post edit/new or not at all.

    Plugin Author Frederick Townes

    @fredericktownes

    Right now, W3TC only empties the cache for the specific post/page you modify. The problem is the benefits of caching are defeated when dozens if not thousands of pages are updated every time you make a change to some page. As a practical matter that process of updating could bring down the entire server or undermine any cache preloading (priming). It’s a non-trivial issue, and a solution is forthcoming. For now you can lower the expire time if you like.

    Frederick, could you perhaps give us some leads as to how to script this ourselves? I am in need of a way to provide non-admin editors with a way to empty all page caches or even all caches.

    If you could tell us what method to call from what context, or maybe something that could work on a filesystem level, that’d be great.

    To answer my own question: You can call w3tc_pgcache_flush() from a hook that you put in your functions.php.

    /* Flush cache when post is saved */
    
    function clearCache($post_ID)  {
    
    	if (function_exists('w3tc_pgcache_flush')) {
    		w3tc_pgcache_flush();
    	} 
    
       return $post_ID;
    }
    
    add_action('wp_insert_post_data', 'clearCache');

    Found this in the thread at
    http://wordpress.org/support/topic/plugin-w3-total-cache-w3tc_pgcache_flush-function-isnt-flushing-cache?replies=6

    Hello
    This plugin is great , but i have i need some other features like:

    is possible that a specific page cache is refreshed when a post is added, so :

    if post = xx category , refresh xx page cache,

    if some one can help how to do this it will be the perfect plugin for me and my team.
    Thank you for reading this e-mail.

    Plugin Author Frederick Townes

    @fredericktownes

    @avin, features like that already exist in the latest release.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: W3 Total Cache] Automatically empty cache when updating posts/pages’ is closed to new replies.
Skip to toolbar