For a while I've been looking for a proper solution to purge the cache of one or several entries in my nginx servers.
The solutions I found were either the commercial ones or some lua modules that didn't look very solid and actually had some security vulnerabilities.
I know that there are projects like ngx_cache_purge, which is even packaged for the official debian repositories, but it does not allow the use of wild cards to purge cache entries.
I already had my own solution using some trickery with cache_bypass to be able to clear the cache of a single URL, but I wanted more.
As I already had some experience with ngx_lua from my nginx_waf module, I decided to create my own lua module to purge caches that allows me to purge both single and multiple entries. It is also easy to deploy and very versatile in the ways you can set it up.
It can work very similar to the commercial solution but of course the performance will be a bit worse and it is for sure not as elegant.
Performance shouldn't be a big issue when clearing caches, but I did the best I could to improve response times in balance with setup easiness and versatility.
In any case it gets the job done with a reasonable performance and security.
Please check it up here: https://github.com/diego-treitos/nginx_cache_multipurge.