• Resolved KratosGemini

    (@kratosgemini)


    We have this option checked:

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

    This is because other pages can be affected (and need to be updated) when a different post gets updated. This usually works well since we don’t update posts all the time.

    However, we have discovered that a plugin we use for logging emails sent by WordPress does so by adding a post (of a custom type) for each email sent. So when we have lots of emails being sent (such as when people are registering for an event), the cache is constantly cleared. As you may imagine, this hurts performance a lot during those times.

    Question: Is there a way to exclude a post type from triggering a cache clear? If so, this would solve the problem with emails clearing our page cache.

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support lastsplash (a11n)

    (@lastsplash)

    Hi @kratosgemini

    You should be able to exclude the custom post type by following the instructions here:

    https://github.com/Automattic/wp-super-cache/wiki/FAQ#how-to-exclude-a-page-from-the-cache

    Let us know how it goes.

    Thread Starter KratosGemini

    (@kratosgemini)

    Thanks, @lastsplash

    I tried what you posted, but it didn’t help. The emails are still clearing the cache for everything. I don’t understand the inner workings of WP Super Cache or our SMTP mailer, but it might be the way the email post type is being generated. I could see why “is_singular(‘postman_sent_mail’)” may never be true if the post is simply made as part of the form processing request (which triggers the email).

    Any other options?

    Plugin Support lastsplash (a11n)

    (@lastsplash)

    Hi @kratosgemini

    Thanks for the additional information. We’re looking into this, but with the weekend, we won’t be able to pick it back up until Monday.

    Just wanted to let you know that we didn’t forget about you.

    Thread Starter KratosGemini

    (@kratosgemini)

    Thanks for looking into it.

    I tried doing a workaround by removing some of the “wp_cache_post_edit” actions before inserting the email log post type by hooking into “wp_insert_post_data” and checking for that post type. However, that does not seem to solve the problem.

    I’m having trouble figuring out what is clearing the cache because it seems like clearing the cache also deletes the WP Super Cache logging. (I enabled logging and then submitted a form to trigger the cache clear to try to see what was going on.) So since the log is cleared whenever the cache is cleared, I don’t know how to diagnose this.

    Again, thanks for looking into it.

    Hey @kratosgemini!

    Sorry it took this long to get back to you. Good news is, this is now doable with the latest version of the plugin (1.9.3).

    We’ve updated the FAQ section of the plugin to include a fix for your specific case here.

    However, this is not a complete solution to the problem, since the homepage will need to be re-cached each time you update a post from the excluded post type. We’ve opened a GitHub issue about that and are currently investigating.

    Thread Starter KratosGemini

    (@kratosgemini)

    Nice! Thanks for the update, @ppetrov2c . I haven’t tried it yet, but we just came up with a workaround that seems to work well (for now anyway). Although it could break if WP Super Cache changes enough, it doesn’t seem to invalidate the homepage cache. I’ll post it here in case anyone else has the issue and needs the homepage to stay cached as well.

    /* Avoid clearing the entire cache when certain post types are inserted */
    function twi_avoid_cache_clear( $data, $postarr, $unsanitized_postarr, $update ) {
    	if ( $data['post_type'] == 'postman_sent_mail' ) {
    		remove_action( 'wp_trash_post', 'wp_cache_post_edit', 0 );
    		remove_action( 'publish_post', 'wp_cache_post_edit', 0 );
    		remove_action( 'edit_post', 'wp_cache_post_change', 0 );
    		remove_action( 'delete_post', 'wp_cache_post_edit', 0 );
    		remove_action( 'publish_phone', 'wp_cache_post_edit', 0 );
    		
    		remove_action( 'clean_post_cache', 'wp_cache_post_edit' );
    		remove_action( 'transition_post_status', 'wpsc_post_transition', 10 );
    	}
    	
    	return $data;
    }
    add_filter( 'wp_insert_post_data', 'twi_avoid_cache_clear', 10, 4);

    That’s great @kratosgemini.

    Thanks for sharing your workaround. ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How to Exclude Post Type from Clearing Cache’ is closed to new replies.