Title: Exclude Cache for Custom Plugin&#8217;s REST API Endpoint
Last modified: February 11, 2019

---

# Exclude Cache for Custom Plugin’s REST API Endpoint

 *  Resolved [robertstaddon](https://wordpress.org/support/users/robertstaddon/)
 * (@robertstaddon)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/exclude-cache-for-custom-plugins-rest-api-endpoint/)
 * 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](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](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fexclude-cache-for-custom-plugins-rest-api-endpoint%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Support [Hai Zheng⚡](https://wordpress.org/support/users/hailite/)
 * (@hailite)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/exclude-cache-for-custom-plugins-rest-api-endpoint/#post-11192846)
 * 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](https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:cache:lscwp:api)
 *  Thread Starter [robertstaddon](https://wordpress.org/support/users/robertstaddon/)
 * (@robertstaddon)
 * [7 years, 4 months ago](https://wordpress.org/support/topic/exclude-cache-for-custom-plugins-rest-api-endpoint/#post-11192878)
 * That worked! Thank you!
 * Here’s my revised function that’s working at [https://test.abundantdesigns.com/wp-json/ld-muvi/v1/test](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;
    }

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.

 * ![](https://ps.w.org/litespeed-cache/assets/icon-256x256.png?rev=2554181)
 * [LiteSpeed Cache](https://wordpress.org/plugins/litespeed-cache/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/litespeed-cache/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/litespeed-cache/)
 * [Active Topics](https://wordpress.org/support/plugin/litespeed-cache/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/litespeed-cache/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/litespeed-cache/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [robertstaddon](https://wordpress.org/support/users/robertstaddon/)
 * Last activity: [7 years, 4 months ago](https://wordpress.org/support/topic/exclude-cache-for-custom-plugins-rest-api-endpoint/#post-11192878)
 * Status: resolved