I am using the open source Nginx as the web server with Proxy_cache.
I have a unique usecase of deleting the key in cache as well as pass the request to the backend servers to delete the key in DB without caching the response.
So delete key in Web server cache and backend DB in same request.
Client => load balancer => Nginx(proxy_cache) => application => PostgreSQL
e.g Nginx.conf
if ( $http_x_delete_key ){
content_by_lua_file ./purge_key.lua;
proxy_pass http://backend_servers;
}
e.g purge_key.lua
...
if ngx ~= nil then
...
delete_file(filename)
ngx.log(ngx.NOTICE, 'deleted')
-- ngx.exit(ngx.OK);
-- return
end
The 'if' block in Nginx location section just stops the flow (How nginx "location if" works) and returns the response without sending it to the backend and is not passing the request as it is.
I have even compiled OpenResty using the free 'ngx_cache_purge' module but the purge command also doesn't pass the request to the backend.
Generally you timeout or refresh the key using the backend response but in my case I need more explicit control to delete the key either in the same request or it's response.
Does Openresty+Memcache, Apache httpd, Apache Traffic Server or Varnish (vcl_purge and pass) solve this usecase or is there some other way to do it?