Support » Plugin: WP REST Cache » Refreshing comments – not working when deleting

  • jacobraccuia



    Once again, thanks for your great plugin.

    I am testing reviews (Woocommerce) and the caching plugin.

    The API Call:

    Setting the object type to comments:

    add_filter( 'wp_rest_cache/determine_object_type', array($this, 'determine_object_type'), 10, 4 );
    function determine_object_type($type, $cache_key, $data, $uri) {
    if('/wp-json/wc/v3/products/reviews' === substr($uri, 0, 31)) {
    	return 'comment';

    When I add a new comment, it works properly. However, when I delete the comment, the cache doesn’t seem to recognize and update.

    And another silly question but – what’s the difference between flushed cache and deleting the actual record?

    When i flush the cache and then run the API call, it doesn’t cache the new results. When I delete the record, it does. Is this expected? I am testing all of the cache functionality and clearing all of the cache with the button seems to be the most efficient way.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Richard Korthuis


    Hi @jacobraccuia

    We haven’t tested our plugin with WooCommerce, so I cannot be certain but as far as I can see in the WC source code they are using the correct WordPress core functions for the comments so it should be working correctly. But as said: I haven’t tested it.

    Could you check the WordPress core endpoint /wp-json/wp/v2/comments and see if that is working correctly and is flushed when you delete a comment?

    Not a silly question: the difference between flushed cache and deleting the actual record:

    • flushed cache: The cache is invalidated, but we do keep some information about the cache record (like how many times it has been requested, which is used to prioritize the cache regeneration if that is activated)
    • delete cache: Not only is the cache invalidated but all data about the cache is deleted from our custom table wp_wrc_caches

    Having said that there shouldn’t be any difference in caching the new results after flushing or deleting the cache record.

    Thread Starter jacobraccuia


    Hi Richard,

    Thanks for the quick reply. I tried very hard to word everything properly, but if you struggle to understand anything please let me know and I’ll adjust. I tested everything to the best that I can to document everything. Everything is tested using postman on a local up to date WP environment.

First issue
    Regarding the WP core endpoint, I tested it and compared to the WC endpoint. Both endpoints have the same object type (comment). Woocommerce reviews are the same as normal comments except they have a few extra fields and are tied to a specific post type.
    The two endpoints I tested are:


    Here is what I learned.

    • Deleting a regular comment on a post triggers the wp/v2/comments URI to flush. It does not trigger the WC reviews URI to flush.
    • Restoring that regular comment (that I deleted) from the trash back to the comments causes both the WP and the WC URI to flush.
    • Deleting a review on a product, specifically a WC review, does not flush the URIs.
    • Restoring that review DOES flush both URIs

    I will see if I can find time to investigate the source code of the cache plugin and WC and compare and see why reviews are acting up.

    Second issue
    I am testing all of the below with: /wp-json/wp/v2/comments

    Regarding flushing / deleting, I am just thoroughly confused and it might be because of a bug. When I delete a record from that table or flush a cache, i start to get mixed results. Sometimes the cached records hit and sometimes they don’t.

    When flushing, specifically, the following happens:

    • Active columns turns to an X
    • Expiration = Flushed

When I call the API from here, I have 2 different outcomes. When I first call it, the call takes a long time and there are no table changes. If I call it immediately after, the # Cache Hits increases by 1 and the call loads the cached result. If I wait a little bit then try again, it goes back to taking a long time. Spamming the send button essentially causes it to cache.
I tested further by editing a comment which normally triggers the cache to tell the API to fetch new content. This made no difference to the flushed record and it still behaves the weird way I illustrated above.

    The only way I am able to get out of this is clicking the Clear REST cache button in the WPAdmin bar. Then, when I call the API, the record loads as intended and Active has the green checkmark and the API calls ALWAYS return the cached result. I was curious what happens in the table when I modify a comment when everything works perfectly, and the table switched to say Flushed and the red X appeared. Yet unlike before, calling the API switched it back to caching properly.

    I can help you debug this further if you’d like proof or access to my environment for debugging purposes.`

    • This reply was modified 6 months, 3 weeks ago by jacobraccuia.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Refreshing comments – not working when deleting’ is closed to new replies.