• Resolved nookyyy

    (@nookyyy)


    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 10 replies - 16 through 25 (of 25 total)
  • Plugin Support qtwrk

    (@qtwrk)

    the POST cache also checks against request body as well , if body changes , it will be miss

    Thread Starter nookyyy

    (@nookyyy)

    Ok how can i narrow down the reason i always get a miss despite the same req body + uri – i dont see any difference on that first filter load

    Plugin Support qtwrk

    (@qtwrk)

    well , that’s good question , after re-think about the issue , I am not sure if plugin was able to handle such request caching

    it has feature to cache POST, it was designed to cache admin-ajax.php POST request, but not sure if it works for other URIs

    I’d suggest to set up a simple admin-ajax POST to test if cache POST works or not first

    for example

    add_action('wp_ajax_nopriv_get_random_number', 'get_random_number_callback');

    function get_random_number_callback() {
    wp_send_json_success(array('number' => rand(1, 10000)));
    }

    then go to cache -> advanced -> ajax cache TTL , put get_random_number 3600

    then curl it like curl -i -X POST -d "action=get_random_number" https://your_domain.com/wp-admin/admin-ajax.php , see if you can get cache hit there first

    • This reply was modified 10 months, 1 week ago by qtwrk.
    Thread Starter nookyyy

    (@nookyyy)

    i think i found out how to do it – found this in another forum:

    CachePost on
    RewriteCond %{REQUEST_URI} ^/wp-json/wpgb/v2/filter/ [NC]
    RewriteRule .* - [E=cache-control:no-vary]

    I had to add those 2 lines aswell – now i get a hit – need to check if it works for different actions / post bodys – will update

    Thread Starter nookyyy

    (@nookyyy)

    ok seems to work so it needs both to work correctly: cache settings in wp plugin + htaccess rule / Apache configuration
    i guess it would be nice if the official doc gets updated with these information 😉

    Then on to the last “problem”: why is my custom rest endpoint not getting cached when i activate cache rest (without the cache uri) / why is full rest endpoint getting purged even though i have all the settings turned off

    Plugin Support qtwrk

    (@qtwrk)

    wasn’t that a POST request to your REST ? that by default won’t , only admin-ajax.php action configured through that cache -> advanced -> admin-ajax cache will be cached by plugin.

    for purge , you got full log on that ?

    Thread Starter nookyyy

    (@nookyyy)

    No my custom endpoint /reviewAPI/v1/ is GET only

    the purge log when i update a post is here: https://pastebin.ubuntu.com/p/RSZMf8zfh3/ ( my custom tag gets added via my function ( and the goal was to purge posts + rest uris depending on what the post changes for other posts )
    and because of the b79_REST TAG the whole REST gets purged. My fix right now is to remove that tag in the header, when one of my custom tag is present.

    Same happens when i delete a post for example:

    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] 💓 ------GET HTTP/1.1 (HTTPS) /wp-admin/post.php
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] Query String: post=11188&action=trash&_wpnonce=d2ebb33bcd
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] HTTP_REFERER: https://nookyyy.com/wp-admin/edit.php?post_type=revie...
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit...
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] Accept Encoding: gzip, deflate, br, zstd
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] Cookie _lscache_vary: admin_bar:1;guest_mode:1;logged-in:1;role:99
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] X-LSCACHE: true
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] LSCACHE_VARY_VALUE: +webp
    05/27/25 17:01:22.815 [87.145.134.193:64444 1 eKS] X-LiteSpeed-Purge: public,stale,b79_Po.11188,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

    • This reply was modified 10 months, 1 week ago by nookyyy.
    Plugin Support qtwrk

    (@qtwrk)

    Thread Starter nookyyy

    (@nookyyy)

    WoW thanks for that info – i guess it would be great to add this info to the docs aswell or maybe even add such an option to the plugin when a user activates the cache rest option.

    Ok but then i know everything i need to know and im able to “work around” those “behaviours” – thanks for your help everything seems to work now on my side just needs a bit more fine tuning to purge what i want / exclude what i need

    Plugin Support qtwrk

    (@qtwrk)

    yeah … I have been chasing after our dev to add a filter to modify the purge header output … it will make everything much easier once it is implemented …

Viewing 10 replies - 16 through 25 (of 25 total)

The topic ‘REST API / PURGE TAG’ is closed to new replies.