• Resolved Bogdan Gerasymenko

    (@kleindberg)


    Hello!

    My question is about Endpoint API Caches and Request URI.

    For example, I have the next URLs:
    /wp-json/wc/v3/orders?page=1&per_page=50 – need to be cached
    /wp-json/wc/v3/orders?per_page=50&search=47983 – don’t cache

    I don’t want that Request URI with search params was cached. Is it possible to avoid caching urls with specific parameters?

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

    (@rockfire)

    Hi @kleindberg

    Thank you for using our plugin!

    At this point there is only one way to avoid caching urls with specific parameters and that is by creating a mu-plugin which uses the filter wp_rest_cache/skip_caching. It has to be a mu-plugin because of the way our plugin works, the caching mechanism is also started from a mu-plugin. So if you would use a normal plugin your code would be executed too late and would have no effect.

    Now how to do it exactly: as said, you need to create a mu-plugin. So create a file named skip_cache_for_search.php in wp-content/mu-plugins. The file can be any name, as long as it is alphabetically before wp-rest-cache.php. In this file you can put the following code:

    <?php
    add_filter( 'wp_rest_cache/skip_caching', 'wprc_skip_cache_for_search' );
    function wprc_skip_cache_for_search( $skip ) {
    	return isset( $_GET['search'] );
    }

    That is it, now all calls to the REST API which contain the search parameter will no longer be cached.

    Thread Starter Bogdan Gerasymenko

    (@kleindberg)

    Thanks for such a quick response. It would be awesome to see paid PRO version of WP REST Cache optimized for WooCommerce API ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Don’t cache Request URI with specific params’ is closed to new replies.