Title: REST API / PURGE TAG
Last modified: May 24, 2025

---

# REST API / PURGE TAG

 *  Resolved [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 3 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/)
 * Hi i got a question regarding caching / purging of rest api calls
 * I would like to cache the rest api, and be able to purge a tag / url. I’ve implemented
   everything and tried both but when the purge is executed the whole rest api endpoint
   is getting purged aswell. I would like to specificly target a tag or an url and
   not purge the whole rest api.
 * It does work, when i turn off “purge rest api” in the cache tab and manually 
   add the endpoint /custom-api/v1/ for example, so my code should be fine?
 * is this a bug or how can i make sure that only the tag / url i want to purge 
   gets purged while keeping the cache of the rest api ?
 * regards

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/rest-api-purge-tag/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/rest-api-purge-tag/page/2/?output_format=md)

 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482601)
 * And another question / bug:
   When i add the uri `/wpgb/v2/filter/?action= 31536000`
   to Force Public Cache URIs or Force Cache URIs it seems to never cache the request
   even though the headers show for example:
 * `x-litespeed-cache-control: public,max-age=31536000`
 * `x-litespeed-tag: b79_default,b79_URL.030bc8deef49f2f27a591f1a251b23ff,b79_REST,
   b79_AJAX.render,b79_`
 * you can check the behaviour here: [https://nookyyy.com/reviews/mouse/](https://nookyyy.com/reviews/mouse/)
   
   the goal would be to add tags to those requests and then be able to purge them
   like the ones for the other rest endpoint see above
 * regards
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482662)
 * but that is an ajax URI , not the REST URI ?
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482694)
 * the endpoint in my first post is 100% rest as its my custom endpoint ( GET call)
 * the 2nd one is `/wp-json/wpgb/v2/filter/?action=render&lang=de` for example (
   POST call )
 * it should be a rest call or maybe they internally req the data via ajax within
   that rest call ( for whatever reason ) ?
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482697)
 * can’t tell anything from surface , but please try grab the debug log , with `
   debug include URI` to specifically target to your REST API, see how log shows
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482711)
 * Ok for the first issue: CACHE REST API in Cache Settings (checked) – Setting 
   Custom TAG to REST CALL on custom REST API (works) – Caching of REST API call(
   works) – PURGING of that TAG (does not work – it clears FULL REST API CACHE) –
   IF i uncheck REST API Cache in settings it does work but the “default” REST API
   does not get cached anymore
 * Log for Rest Call: [https://pastebin.ubuntu.com/p/ZT3Z8kVvZf/](https://pastebin.ubuntu.com/p/ZT3Z8kVvZf/)
 * Log for PURGE: [https://pastebin.ubuntu.com/p/RSZMf8zfh3/](https://pastebin.ubuntu.com/p/RSZMf8zfh3/)
 * Function to purge used:
 * ` _foreach_ ($tags_to_purge as $tag) { `
 * `$debug_string .= 'PURGE REST TAG: ' . $tag . "\n";`
 * `_do\_action_('litespeed_purge', $tag); }`
    -  This reply was modified 10 months, 2 weeks ago by [nookyyy](https://wordpress.org/support/users/nookyyy/).
    -  This reply was modified 10 months, 2 weeks ago by [nookyyy](https://wordpress.org/support/users/nookyyy/).
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482721)
 * huh ?
 * if you don’t see any purge log , maybe the function is not executed ?
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482723)
 * i see the log when i removed the uri from the debug uri inclued – edited my post
 * i can see that the TAG b79_REST is added – but WHY – when i dont execute my function
   this does not happen so its not that just by saving the post the rest data gets
   purged
    -  This reply was modified 10 months, 2 weeks ago by [nookyyy](https://wordpress.org/support/users/nookyyy/).
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482729)
 * what if you do a standalone purge ? just for test
 * like
 *     ```wp-block-code
       <?phprequre('./wp-load.php');do_action('litespeed_purge', 'xxx'); 
       ```
   
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482754)
 * That does work
 * `05/25/25 15:21:44.764 [=CLI= 1 1od] X-LiteSpeed-Purge: public,stale,b79_REST_ITEMSPEC_11029
   => LiteSpeed\LSC->send_headers()@603 => WP_Hook->apply_filters(,ARRAY)@324 =>
   WP_Hook->do_action(ARRAY)@348 =>
   /var/www/vhosts/nookyyy.com/httpdocs/wp-includes/
   load.php@517
 * 
   i did some more debuging – it seems like the purge call does actually just gets
   triggered when i save my post
 * `05/25/25 15:34:35.473 [87.145.134.193:64666 1 JIp] 💓 ------POST HTTP/1.1 (HTTPS)/
   wp-admin/post.php
   05/25/25 15:34:35.473 [87.145.134.193:64666 1 JIp] Query String:
   05/25/25 15:34:35.473 [87.145.134.193:64666 1 JIp] HTTP_REFERER: https://nookyyy.
   com/wp-admin/post.php?post=11029&acti...05/25/25 15:34:35.474 [87.145.134.193:
   64666 1 JIp] X-LiteSpeed-Purge: public,stale,b79_Po.11029,b79_URL./reviews/mouse/
   lamzu/inca/,b79_W.recent-posts-1,b79_FD,b79_REST => LiteSpeed\LSC->send_headers()
   @603 => WP_Hook->apply_filters(,ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =
   >/var/www/vhosts/nookyyy.com/httpdocs/wp-includes/load.php@517
 * but i turned off
 * Purge All On Upgrade, unchecked everything in Auto Purge Rules For Publish/Update
   and cleared Purge All Hooks field aswell.
    -  This reply was modified 10 months, 2 weeks ago by [nookyyy](https://wordpress.org/support/users/nookyyy/).
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482772)
 * That does work
 * `05/25/25 15:21:44.764 [=CLI= 1 1od] X-LiteSpeed-Purge: public,stale,b79_REST_ITEMSPEC_11029
   => LiteSpeed\LSC->send_headers()@603 => WP_Hook->apply_filters(,ARRAY)@324 =>
   WP_Hook->do_action(ARRAY)@348 =>
   /var/www/vhosts/nookyyy.com/httpdocs/wp-includes/
   load.php@517
 * 
   i did some more debuging – it seems like the purge call does actually just gets
   triggered when i save my post
 * `05/25/25 15:34:35.473 [87.145.134.193:64666 1 JIp]  ------POST HTTP/1.1 (HTTPS)/
   wp-admin/post.php
   05/25/25 15:34:35.473 [87.145.134.193:64666 1 JIp] Query String:
   05/25/25 15:34:35.473 [87.145.134.193:64666 1 JIp] HTTP_REFERER: https://nookyyy.
   com/wp-admin/post.php?post=11029&acti...05/25/25 15:34:35.474 [87.145.134.193:
   64666 1 JIp] X-LiteSpeed-Purge: public,stale,b79_Po.11029,b79_URL./reviews/mouse/
   lamzu/inca/,b79_W.recent-posts-1,b79_FD,b79_REST => LiteSpeed\LSC->send_headers()
   @603 => WP_Hook->apply_filters(,ARRAY)@324 => WP_Hook->do_action(ARRAY)@348 =
   >/var/www/vhosts/nookyyy.com/httpdocs/wp-includes/load.php@517
 * but i turned off
 * Purge All On Upgrade, unchecked everything in Auto Purge Rules For Publish/Update
   and cleared Purge All Hooks field aswell.
 * Update:
   so i was able to find a “hack” to make sure when my tags are added that
   not the whole rest endpoint gets purged – but i still wonder y a post save with
   my settings triggers so many purge tags
 *     ```wp-block-code
       // Modify LiteSpeed purge headersif (strpos($_SERVER['REQUEST_URI'], "LSCWP_NONCE") === false) {    ob_start(function($buffer) {        // Get the current purge header if it exists        $current_header = '';        foreach (headers_list() as $header) {            if (stripos($header, 'X-LiteSpeed-Purge:') !== false) {                $current_header = $header;                break;            }        }        // Extract any REST_ITEMSPEC or REST_TEMPLATE or REST_TEMPLATEtags        $purge_tags = [];        if (preg_match_all('/REST_(ITEMSPEC|TEMPLATE|DROPDOWN)_\d+/', $current_header, $matches)) {            $purge_tags = $matches[0];        }        // If we found matching tags, build new purge header        if (!empty($purge_tags)) {            $tags = implode(',b79_', $purge_tags);            @header('X-LiteSpeed-Purge: public,stale,b79_' . $tags);        }        return $buffer;    });}
       ```
   
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18482948)
 * I still cant figure out why the other endpoint is not getting cached.
 * when i activate cache rest api calls in the cache tab a call like this should
   get cached correct? because its not getting cached either
 * [https://nookyyy.com/wp-json/wp/v2/review/11029](https://nookyyy.com/wp-json/wp/v2/review/11029)
 * Log of all 3 Calls: [https://pastebin.ubuntu.com/p/8bfGVbNJW8/](https://pastebin.ubuntu.com/p/8bfGVbNJW8/)
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18483951)
 * eh , sorry , one thing at the time
 *     ```wp-block-code
       9 => 'X-LiteSpeed-Cache-Control: public,max-age=31536000',10 => 'X-LiteSpeed-Tag: b79_default,b79_URL./wp-json/wpgb/v2/filter/,b79_REST,b79_AJAX.render,b79_',
       ```
   
 * it is getting cached , no ? what do you see on response header?
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18484147)
 *     ```wp-block-code
       Sure, response Heaaders for that request are ALWAYS:access-control-allow-headers: Authorization, X-WP-Nonce, Content-Disposition, Content-MD5, Content-Typeaccess-control-expose-headers: X-WP-Total, X-WP-TotalPages, Linkcache-control: public, max-age=3600content-encoding: brcontent-security-policy: upgrade-insecure-requestscontent-type: application/json; charset=UTF-8date: Mon, 26 May 2025 12:10:14 GMTexpect-ct: enforce, max-age=21600expires: Wed, 11 Jan 1984 05:00:00 GMTlink: <https://nookyyy.com/wp-json/>; rel="https://api.w.org/"permissions-policy: geolocation=(), midi=(),sync-xhr=(),accelerometer=(), gyroscope=(), magnetometer=(), camera=(), fullscreen=(self)pragma: publicreferrer-policy: strict-origin-when-cross-originserver: LiteSpeedstrict-transport-security: max-age=15768000; includeSubDomainsvary: Accept-Encoding,User-Agentx-content-type-options: nosniffx-frame-options: sameoriginx-litespeed-cache-control: public,max-age=31536000x-litespeed-tag: b79_default,b79_URL.030bc8deef49f2f27a591f1a251b23ff,b79_REST,b79_AJAX.render,b79_x-powered-by: PHP/8.3.21x-robots-tag: noindexx-xss-protection: 1; mode=block
       ```
   
 * I never get the
 * `x-litespeed-cache: hit or miss`
 * regards
 *  Plugin Support [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * (@qtwrk)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18485559)
 * I see, that is a POST request, you need to enable [this](https://docs.litespeedtech.com/lscache/devguide/advanced/#caching-post-responses)
 *  Thread Starter [nookyyy](https://wordpress.org/support/users/nookyyy/)
 * (@nookyyy)
 * [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/#post-18485703)
 * Ok thx – activated that and now i get:
 * `x-litespeed-cache: miss`
 * every time for the same POST Req. ( would the server still cache based on the
   req uri or based on the uri + post data ? ) ( simply the filter req on the main
   load: [https://nookyyy.com/reviews/mouse/](https://nookyyy.com/reviews/mouse/))

Viewing 15 replies - 1 through 15 (of 25 total)

1 [2](https://wordpress.org/support/topic/rest-api-purge-tag/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/rest-api-purge-tag/page/2/?output_format=md)

The topic ‘REST API / PURGE TAG’ 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/)

## Tags

 * [cache](https://wordpress.org/support/topic-tag/cache/)
 * [Purge](https://wordpress.org/support/topic-tag/purge/)

 * 25 replies
 * 2 participants
 * Last reply from: [qtwrk](https://wordpress.org/support/users/qtwrk/)
 * Last activity: [10 months, 2 weeks ago](https://wordpress.org/support/topic/rest-api-purge-tag/page/2/#post-18489439)
 * Status: resolved