5

I am looking for a way to purge nginx cache using by adding a specific annotation on url.

Let's say I have this url (item) cached with nginx:

http://mywebsite/render/render5.php?frame=1&image=nature-1920.jpg

If I want to purge it, I would have to add:

http://mywebsite/render/render5.php?frame=1&image=nature-1920.jpg&purge=1

Is that possible to purge an URL if we add at the end of this URL &purge=1?

All tutorials I find use the curl -X command to purge a specific item, for example:

curl -X PURGE http://mywebsite/render/render5.php?frame=1&image=nature-1920.jpg

https://scene-si.org/2016/11/02/purging-cached-items-from-nginx-with-lua/

And I want to be able to purge an nginx cached item (url) without having to use curl -X command.

London Smith
  • 217
  • 1
  • 4
  • 8

1 Answers1

2

The linked tutorial adds the purge feature using a Lua script, so it would be possible to modify it to use &purge=1 instead of PURGE http method. However, it's not advisable for a production system.

A guiding principle of HTTP/REST service design is that GET requests (ie what happens when you call curl <url>) are "safe", meaning they should basically be read-only without any side effects. One reason for this is that clients may call them in advance, e.g. a web browser is at liberty to call URLs shown on a page as soon as it loads, as a performance boost. This would purge the cache.

mahemoff
  • 197
  • 11