Support » Plugin: Cache Enabler » Question about posts generated via import job

  • Resolved magicoders



    We’re running a daily import job that updates all of a custom post type “listing” on a site.

    The import plugin does trigger functions like save_post programmatically, however, the cache is not cleared when the import runs, and the old listings are kept visible instead of the updated ones.

    I can see all the folders for each post are correctly generated under cache/cache-enabler/, however they are not being recreated with the import.

    Looking at the available hooks I am wondering which would be the ideal approach here to programmatically clear these html folders/files under cache/cache-enabler/ and wondering if you have any insight.

    We could also clear the folders via php but for future compatibility, would prefer to use in-built Cache Enabler methods if possible.

    Thank you! I am just starting to get acquainted with this plugin, but so far it’s looking like a very smart and nicely made solution πŸ™‚

    • This topic was modified 2 years, 2 months ago by magicoders.
Viewing 5 replies - 1 through 5 (of 5 total)
  • If the save_post hook is fired and the post status is publish the cache should be cleared. By default it would be the page and associated cache or the site cache if the setting is enabled. The Cache Enabler plugin doesn’t recreate the cached pages after they’ve been cleared. A request to the pages is required to cache the page again.

    Before I provide an example on how to extend Cache Enabler to effectively clear your pages cache in this case, what are you using for the import job? Details on how to replicate the issue would be helpful. On the top of my head, if the post status is publish when the save_post hook is fired, meaning the post is being updated, maybe Cache Enabler isn’t initialized yet?

    Regarding your feedback, thank you for sharing that. I’m really happy to hear that you’re enjoying Cache Enabler. πŸ™‚ Once you feel like you’ve had enough time to use Cache Enabler we’d love to get your feedback in an honest review. That is always helpful and appreciated.

    Thread Starter magicoders


    I think you’re on the right track re: the post is being updated, maybe Cache Enabler isn’t initialized yet.

    Thanks for clarifying the plugin behavior too. As far as I see, deleting all folders under listings/ should work great, to ensure deleted listings are not cached, and that updated ones get recreated on first request.

    I’m using WP All Import with customizations, although I don’t think these are relevant for the cache behavior. Can share about them too though, if needed.

    Thank you very much for your time and help.

    Thanks for the additional information. Without replicating the issue I can’t say for certain why this is occurring, but extending Cache Enabler is easy to do since the major refactor that was completed at the end of last year.

    In this case I’d recommend trying the snippet below. It takes the pmxi_saved_post hook from WP All Import and then calls clear_cache_on_post_save(), which is the same method that is called in on_save_post() when the save_post hook is fired if the post status is publish:

    add_action( 'pmxi_saved_post', 'cache_enabler_clear_imported_pages_cache' );
    function cache_enabler_clear_imported_pages_cache( $post_id, $xml_node, $is_update ) {
        if ( $is_update ) {
            Cache_Enabler::clear_cache_on_post_save( $post_id );
    Thread Starter magicoders


    This looks perfect. Even if that exact snippet does not work, just knowing that there is no “flush all folders for a specific cpt”, and that you recommend using Cache_Enabler::clear_cache_on_post_save( $post_id ); is the information I was after.

    Thanks for the thoughtful support, it’s much appreciated.

    You’re most welcome! Always happy to help. Just for an extra bit of information, in most cases the cache_enabler_clear_page_cache_by_post_id hook would be my recommendation, but in this case if the same Cache Enabler behavior that would normally occur when a post is saved is desired then that is where the recommendation above comes in.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Question about posts generated via import job’ is closed to new replies.