Wordpress LScache Plugin: Exclude Cache for Custom Plugins REST API Endpoint
Last Updated on: Wed, 15 Apr 2026 00:00:02 I am creating a WordPress plugin that registers a new WordPress REST API endpoint that returns some basic information. Its 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. Im still getting a x-litespeed-cache: hit in the header. See https://test.abundantdesigns.com/wp-json/ld-muvi/v1/test Heres the callback code thats 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: https://test.abundantdesigns.com/wp-json/ld-muvi/v1/test Hi, Did you try to call our API no cache func LiteSpeed_Cache_API::set_nocache() ? Ref: https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:api That worked! Thank you! Heres my revised function thats working at https://test.abundantdesigns.com/wp-json/ld-muvi/v1/test public function test_callback( $data ) $response[result] = Connection successful $response[random-number] = rand(1000, 9999) if ( class_exists( LiteSpeed_Cache_API ) ) LiteSpeed_Cache_API::set_nocache() $response[litespeed] = Successfully disabled LiteSpeed Cache on page $result = new WP_REST_Response( $response, 200 ) // Set headers. $result->set_headers( array( Cache-Control => no-cache, must-revalidate, max-age=0 ) ) return $result
LiteCache Rush: Speed comes from using less, not from doing it faster
Reference