invalidateTags() HTTP call parameter seems buggy

Created on 26 February 2024, 10 months ago
Updated 4 April 2024, 9 months ago

I'm just reporting this here for time efficiency, haven't been testing it myself, so I don't know how to phrase what is wrong exactly. Because I don't know the exact syntax for the pullzone/%s/purgeCache API call.

Feel free to credit @fago instead of me, he tested.

Problem/Motivation

When trying to purge cache tags node:130 + anothertag + yetanothertag +etc, the node:130 didn't get purged as intended.

Contact with BunnyCDN support got the response " Can you please share [...] are you doing node:130 or are you not doing *node:130*?"

It turns out that when sending the tag as "*node:130 *", this works for us. Not only for the first tag purged, also for the rest. (I guess that figures because they're all separate HTTP calls. Again: I'm just reporting literally what I heard/read because I don't know the exact details of the call.)

Proposed resolution

See upcoming MR. (Yes, we've left the trailing space in, while removing the leading space.)

To be fully transparent: we now have custom code overriding some stuff, for... reasons. Our custom code did

$this->request('POST', "pullzone/$pullZone/purgeCache", [
      RequestOptions::JSON => [
        'CacheTag' => "* $tag *",
      ],

which did not work, per above, but now works with

$this->request('POST', "pullzone/$pullZone/purgeCache", [
      RequestOptions::JSON => [
        'CacheTag' => "*$tag *",
      ],

...where $tag = $invalidation->getExpression(). That really should translate literally to the sprintf that you're doing, unless I'm going mad.

Remaining tasks

Judge if this syntax is fine according to you.

(We don't need a new release per se, our code is good for now. So do what you want.)

🐛 Bug report
Status

Fixed

Version

1.1

Component

Code

Created by

🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @roderik
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    roderik changed the visibility of the branch 3423820-invalidatetags-http-call to hidden.

  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    roderik changed the visibility of the branch 3423820-invalidatetags-http-call to active.

  • Status changed to Needs review 10 months ago
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU
  • Status changed to RTBC 10 months ago
  • 🇦🇹Austria fago Vienna

    We ran into in issue with a cache-tag not being purged, this fixes the issue nicely and should be quite safe - main thing is we keep the space in the suffix!

  • 🇧🇪Belgium dieterholvoet Brussels

    Yeah, that makes sense. Only problem I could think about is that now, when invalidating node:130, it would invalidate any cache tags that end with node:130. For example something_node:130 would be invalidated as well. Seems rather rare in this case, but still, it wouldn't be ideal to leave this in. That would be a hard to debug issue if it ever happens.

    The 100% correct way seems to me to do three requests: one in case the cache tag we're invalidating is the first one, one if it's in the middle and one if it's the last one.

    $this->request('POST', "pullzone/$pullZone/purgeCache", [
          RequestOptions::JSON => [
            'CacheTag' => "$tag *",
          ],
    
    $this->request('POST', "pullzone/$pullZone/purgeCache", [
          RequestOptions::JSON => [
            'CacheTag' => "* $tag *",
          ],
    
    $this->request('POST', "pullzone/$pullZone/purgeCache", [
          RequestOptions::JSON => [
            'CacheTag' => "* $tag",
          ],
    

    I just checked and pricing doesn't seem to depend on the amount of API calls or the amount of purges, so I don't think it would be a problem to do three API calls instead of one. What do you think?

  • Status changed to Needs review 10 months ago
  • 🇳🇱Netherlands roderik Amsterdam,NL / Budapest,HU

    LOL. I didn't get 'the syntax for that purge command' until I read your last message. I only now realize that BunnyCDN stores the whole string as a single tag.

    Well in that case... I think instead of doing 3 requests, we can and should make sure the BunnyCDN tag starts and end with a space, so that the current * DRUPAL-CACHETAG " purge command always works?

    See new proposal in the next commit, for your review of concept. (Untested so far, but I don't see why it shouldn't work.)

  • 🇧🇪Belgium dieterholvoet Brussels

    Looks good! Let me know if you were able to test this in practice and I'll merge it. I'm not doing cache tag based invalidations anymore on my project, so I don't have an easy way to test this.

  • Status changed to RTBC 9 months ago
  • 🇦🇹Austria fago Vienna

    That's indeed better! We've tested the updated patch successfully to work correctly, so back to RTBC.

  • Pipeline finished with Skipped
    9 months ago
    #125142
  • Status changed to Fixed 9 months ago
  • 🇧🇪Belgium dieterholvoet Brussels

    Thanks!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024