Support » Plugin: LiteSpeed Cache » Exclude Cache for Custom Plugin’s REST API Endpoint

  • Resolved robertstaddon

    (@robertstaddon)


    I am creating a WordPress plugin that registers a new WordPress REST API endpoint that returns some basic information. It’s important that this endpoint is not cached because the information will be changing often and needs to be up to date.

    I use LiteSpeed caching on my server with this LiteSpeed plugin. I would prefer not to tell everyone with LiteSpeed caching that they must manually add an exclusion for this endpoint to keep it from being cached. Is there any kind of header that I could add that would tell LiteSpeed not to cache this endpoint? I tried “Cache-Control: no-cache, must-revalidate, max-age=0” and “X-LiteSpeed-Cache-Control: no-cache” without success. I’m still getting a “x-litespeed-cache: hit” in the header. See https://test.abundantdesigns.com/wp-json/ld-muvi/v1/test

    Here’s the callback code that’s being used for the endpoint and being cached by LiteSpeed:

    public function test_callback( $data ) {

    $response[‘result’] = ‘Connection successful’;
    $response[‘random-number’] = rand(1000, 9999);

    $result = new WP_REST_Response( $response, 200 );

    // Set headers.
    $result->set_headers( array(
    ‘Cache-Control’ => ‘no-cache, must-revalidate, max-age=0’,
    ‘X-LiteSpeed-Cache-Control’ => ‘no-cache’
    ) );

    return $result;
    }

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Exclude Cache for Custom Plugin’s REST API Endpoint’ is closed to new replies.