Support » Plugin: WP REST Cache » Deleting the record

Viewing 9 replies - 1 through 9 (of 9 total)
  • I face similar issue:

    Once a record related to an object type with custom endpoint is deleted, it is still cached and the cached endpoint is not flushing automatically. I noticed the auto-flushing of the cache is happening whenever an object’s record is created or edited. I need similar solution for the delete action as well. Any solution?

    Plugin Author Richard Korthuis


    Hi @radha2914 and @shyamla

    Thank you for using our plugin!

    If we are talking about the default WordPress endpoints, the cache record should be automatically deleted by our plugin. So for instance if you delete a page with ID = 42 and there is a cache for /wp-json/wp/v2/pages/42 then this cache should automatically be deleted by our plugin. Is this not the case for you?

    If we are talking about a custom endpoint then there are multiple solutions / causes for the problem:

    1. Does your endpoint contain a (custom) post type or (custom) taxonomy? Then please make sure the plugin can detect the correct object type. See our FAQ about how you can help the plugin detect it correctly. Once that is done the plugin should be able to automatically flush or delete the cache (depending whether it was edited or deleted).
    2. If that is not possible for you, you could trigger the deletion of the cache yourself. Upon deletion of the record you can tell the plugin to delete all related caches: \WP_REST_Cache_Plugin\Includes\Caching\Caching::get_instance()->delete_related_caches( 42, 'my_custom_post_type', true);

    Please let us know if you need more help, or when it is not working (correctly) for you

    Thanks for your reply. Our custom endpoint looks something similar to this:


    We have added from the plugin FAQ like this:

    function wprc_add_endpoint( $allowed_endpoints ) {
        if ( ! isset( $allowed_endpoints[ '<custom_namespace>' ] ) || ! in_array( 'posts', $allowed_endpoints[ '<custom_namespace>' ] ) ) {
            $allowed_endpoints[ '<custom_namespace>' ][] = '<custom_name>';
        return $allowed_endpoints;
    add_filter( 'wp_rest_cache/allowed_endpoints', 'wprc_add_endpoint', 10, 1);

    Adding this helped the plugin to identify the custom object (post) type, thereby allowing the plugin to flush the cache whenever the post/record is created or edited. But not while deletion. We still needed to wait till the next scheduled flush (We set that as 1 hour).

    Note: We are not using any other custom code to perform the CRUD operations.

    • This reply was modified 8 months, 3 weeks ago by shyamla.
    Plugin Author Richard Korthuis


    Hi @shyamla

    Well that is step 1, you have told the plugin to also cache your custom endpoint. But when you visit Settings > WP REST Cache > Endpoint API Caches in you wp-admin and search for a cache record for your custom endpoint, what do you see under “Object Type”? If it says unknown it still isn’t able to determine the correct object type.
    If it displays the correct object type, then we have to look further as to why it is not being deleted correctly. After deleting the record how do you determine the cache is still there? Did you look at Settings > WP REST Cache > Endpoint API Caches in you wp-admin and was is still there?

    Yes, it is determining the correct object type. But once we delete the record, both in the endpoint and in the cache details’ cache data, we could notice the data is still cached.

    Plugin Author Richard Korthuis


    Hi @shyamla

    And that object type, is it a (custom) post type or a (custom) taxonomy? (Just double-checking)

    I just did some tests and for me the endpoint caches are all being deleted just as expected. So I suspect there is some other code which is causing this behaviour. We can try to have the cache deleted even sooner by changing the priority of our add_action. Could you try and edit /includes/class-plugin.php on line 144 it says:
    add_action( 'delete_post', [ $caching, 'delete_post' ] );
    could you change that to:
    add_action( 'delete_post', [ $caching, 'delete_post' ], 1 );
    and then retry if the cache is deleted once the post is deleted?

    Hi @rockfire

    We are using the custom post type. We have changed the code (line 144) and deleted the record in the custom post type. still, we could notice the data is cached. It did not clear the cache as well.

    Plugin Author Richard Korthuis


    Hi @shyamla

    Sorry for not getting back to you any sooner. We did some extensive testing but were unable to reproduce your situation. Unfortunately that makes it impossible for us to determine the cause and implement a fix for it.
    Did you by any chance find the cause?

    Hi Richard,

    Thank you so much for your reply, I could not find the cause. I have followed all your instructions, uninstalled other plugins and cross-checked everything. Still, we are facing the same issue.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Deleting the record’ is closed to new replies.