0

I have the following type of endpoints.

/v1/endpoint/{id}/cache

/v1/endpoint/{id}/bypasscache

I want to bypass the cache on the second one as it needs to be up to date, whilst keeping my default cache on the first url which is updated infrequently.

Is this possible to have this setup, but with variable id?

if ($request_uri ~* "/v1/endpoint/18/bypasscache" ) {
  set $no_cache 1;
}

fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;
Paul
  • 578
  • 1
  • 8
  • 23

1 Answers1

1

Try (for variable ids in 1 or 2 character wide combinations of numbers, lower and upper case ascii letters):

if ($request_uri ~* "/v1/endpoint/[0-9a-zA-Z]{1,2}/bypasscache" ) {
  set $no_cache 1;
}

fastcgi_cache_bypass $no_cache;
fastcgi_no_cache $no_cache;

untested as I currently cannot start a spare web service ;-)

Other hints may be found in answers to nginx location regex - character class and range of matches

Also there is the hint on not forgetting to quote the string when it contains curly braces in the regex, as these might interfere with the block syntax curly braces - here the block of the if ...

Community
  • 1
  • 1
Dilettant
  • 3,267
  • 3
  • 29
  • 29