• Resolved raratiru

    (@raratiru)


    When updating a product using Woocommerce API, the cache page of the product is not cleared.

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter raratiru

    (@raratiru)

    Update:

    The home page is not cleared, the page of the product is cleared.

    The cache had expired and it seemed that the product updated successfully.

    The issue is that using the API to update a product, the relevant caches are not cleared.

    • This reply was modified 4 years, 3 months ago by raratiru.
    Anonymous User 16850768

    (@anonymized-16850768)

    Since version 1.4.0 the home page (or complete cache) is not cleared when any post type has been updated. You can learn more about why this change was introduced in my explanation here.

    To troubleshoot this further, can you please provide the steps required to replicate this issue? Furthermore, explicit details on the issue occurring and the expected behavior, like what you consider the relevant caches to be, would also be helpful.

    Thread Starter raratiru

    (@raratiru)

    Thank you, the code provided in the link is a good start.

    Regarding that post I have 2 questions:

    * What is the function that should be called on post_save to clear all cache?
    * Is it possible to get the id of the post that is saved and dynamically pass it to clear_home_page_cache_on_save_post() to clear that too, along with the home page?

    =====

    To replicate the issue, use the Woocommerce Rest API to update a product:

    curl -X PUT https://example.com/wp-json/wc/v3/products/794 \
        -u consumer_key:consumer_secret \
        -H "Content-Type: application/json" \
        -d '{
      "featured": "True",
      "sku": "123456789"
    }'

    The cache of product 794 will not be cleared.

    • This reply was modified 4 years, 3 months ago by raratiru.
    Anonymous User 16850768

    (@anonymized-16850768)

    You’re most welcome, @raratiru. The linked post was more so intended to inform you (or others) about why the the home page or complete cache is not cleared on any post type updates and to follow the updates regarding that topic there. The provided snippet in that topic was related to that use case.

    The complete cache can be cleared by calling the ce_clear_cache action hook.

    Yes, the save_post action hook passes the post ID so this can be the parameter in your callback function, however, the page cache of an updated post is already cleared by default with the publishing action.

    Thank you for the example regarding the WooCommerce API. Please let me troubleshoot this further. Additional updates to follow.

    Thread Starter raratiru

    (@raratiru)

    Thank you!

    Since we do not manually update or save any products, I added the snippet:

    function clear_page_cache_on_update_post( $post_ID, $post, $update ) {
      if ( $update ) {
        do_action( 'ce_clear_post_cache', $post_ID );
      }
    }
    
    add_action( 'save_post', 'clear_page_cache_on_update_post', 10, 3 );

    Which clears the cache on update through the API until further updates incorporate it in the plugin. Please, post here if updates occur!

    Thread Starter raratiru

    (@raratiru)

    @coreyk In an effort to clean the homepage on product update (especially for the price to appear correctly), I followed the linked example.

    The issue is that my homepage is paginated and calling:

    do_action( 'ce_clear_post_cache', $home_page_ID );

    … only the cache of the first page of the homepage is cleared.

    Is there a way to clear the cache of all pages of the home page?

    • This reply was modified 4 years, 3 months ago by raratiru.
    Anonymous User 16850768

    (@anonymized-16850768)

    After investigating this issue further I can confirm that as of version 1.4.8 the cache would not be cleared if any post type is updated (or even published) through an API (WooCommerce or even WordPress). As far as I can tell this has been the functionality since version 1.0.0. Turns out this ties into what I discovered a few days ago, where I believe significant improvements can be made around clearing the cache for publishing and updating actions (including clearing pagination pages). Please follow the progress of this change in issue #112 on GitHub.

    Thread Starter raratiru

    (@raratiru)

    OK thank you, I mark this as resolved and I will be waiting for the outcome of #112!

    • This reply was modified 4 years, 3 months ago by raratiru.
Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Updating through the API, will not clear page cache’ is closed to new replies.