• Hi,

    Is it possible to set different Cache timeouts for different endpoints? At the moment, there is just one setting in the plugin to set the timeout – https://prnt.sc/8am7yd6hir6V

    Similar to registering custom endpoints using filters, can different timeouts be specified like that?

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

    (@rockfire)

    Hi @temak

    Thank you for using our plugin!

    Yes, there is a filter for that! You could do something like this:

    /**
    * Set a different cache timeout for the posts endpoint.
    *
    * @param int $timeout The timeout as set in the settings.
    * @param array $options An array of options, containing the current uri, the object type, the request headers and the request method.
    *
    * @return int
    */
    function wprc_set_posts_timeout( $timeout, $options ) {
    /**
    * Available keys in $options are: uri, object_type, request_headers, request_method
    */
    if ( 'posts' === $options['object_type'] || '/wp-json/wp/v2/posts' === $options['uri'] ) {
    $timeout = MONTH_IN_SECONDS;
    }
    return $timeout;
    }

    add_filter( 'wp_rest_cache/timeout', 'wprc_set_posts_timeout', 10, 2 );
    Thread Starter Timi Makinde

    (@temak)

    Oh perfect @rockfire i’ll try that out but that’s exactly what I need from the looks of it. Great work with the plugin!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Set different Cache timeout for different endpoints’ is closed to new replies.