WordPress.org

Ready to get started?Download WordPress

Forums

WP Super Cache
Clear all cache should'nt be executed on a draft post (8 posts)

  1. Daniel Roch
    Member
    Posted 2 years ago #

    Hello,

    I'm using WP Super Cache with this setting :

    Clear all cache files when a post or page is published or updated

    When I update a draft post, all the cache is cleared. But this plugin should'nt work this way. In order to publish a new post, I usually write during a few hours, and I may save this post a lot of time. Each time I do so, the cache is cleared (and becomes useless).

    Can it be fixed ?

    Regards,

    http://wordpress.org/extend/plugins/wp-super-cache/

  2. James Revillini
    Member
    Posted 2 years ago #

    You know you don't need to have the 'Clear all cache files when a post or page is published or updated' option set if you only care about updating the cache for the current page/post you're working on, right? It will clear the cache of just that page when you save it.

  3. Daniel Roch
    Member
    Posted 2 years ago #

    I know that it's not compulsory.

    But on my website I need to empty the cache when i publish or update a post, because there is many links between each of my post and because my cache timeout last a few days.

    The "Clear all cache files when a post or page is published or updated" shouldn't work this way on a draft postn, beacause there is no need to empty a cash when a user is updating an invisible post...

  4. James Revillini
    Member
    Posted 2 years ago #

    Confirming the bug. I tested @Confridin's issue against dev version of plugin and this does in fact happen. I can also say it's not happening where you would expect. I thought there would be a bug in wp_cache_post_change, but there are checks to see if the item has a status of 'publish' and it leaves the function if it does not. So the issue is somewhere else.

  5. James Revillini
    Member
    Posted 2 years ago #

    OK I figured it out. If you want to patch your code, you can do it with this...

    in wp-cache-phase2.php, find

    function wp_cache_post_edit($post_id) {
    	global $wp_cache_clear_on_post_edit, $cache_path, $blog_cache_dir;

    Right below the declaration of globals, add

    $post = get_post( $post_id );
    	if( $post->post_status != 'publish' ) {
    		if ( isset( $GLOBALS[ 'wp_super_cache_debug' ] ) && $GLOBALS[ 'wp_super_cache_debug' ] ) wp_cache_debug( "wp_cache_post_change: draft post, not deleting any cache files.", 4 );
    		return $post_id;
    	}

    Note: copied code from wp_cache_post_change in same file.

  6. Daniel Roch
    Member
    Posted 2 years ago #

    Thanks for your help jrevillini. It works !

    Can this code be included in a new version of the plugin by the author ?

  7. James Revillini
    Member
    Posted 2 years ago #

    I think it would be great if he thinks the code wouldn't introduce new bugs. Leave the thread unresolved so he reads it and maybe lets us know his plans.

  8. Donncha O Caoimh
    Member
    Plugin Author

    Posted 2 years ago #

    Thanks jrevillini, I just added this to the development version!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic