• Resolved Cris

    (@ctagupa)


    Is it possible to set a specific Cache timeout for a certain endpoint?

    Like Category / Tags, example I’d like tags to set for 15 mins. then the rest of the endpoints to like 1 yearm is that possible?

    Thanks!

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

    (@rockfire)

    Hi @ctagupa

    Thank you for using our plugin!

    Yes that is possible using the filter wp_rest_cache/timeout For example 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 );
Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.