FRiCKLE/ngx_cache_purge

Is it possible to purge Nginx cache based on partial part of proxy_cache_key

Indrani123 opened this issue · 0 comments

I am working on Nginx , used Nginx cache,Now I want to purge this cache based on partial cache key, so I had use ngx_cache_purge module of Nginx I have the following code:

 proxy_cache_path /tmp/cache levels=1:2 keys_zone=cache:60m max_size=1G;

 server {

    listen       8888;

    server_name  localhost;

    location / {
    add_header X-nginx-Cache $upstream_cache_status;
    proxy_cache          cache;
    proxy_cache_key   $request_uri$http_x_authorization;
    proxy_pass_request_headers      on;
    proxy_cache_valid 200 302 10m;
    proxy_pass  http://localhost:9000;
    proxy_cache_purge   PURGE from 127.0.0.1;
    }

 }

I want to purge cache based on request_uri which is also a part of cache_key, I dont want to worry about http_x_authorization because it is a token from authorization framework,which is hard to remember

I tried with curl command :

     curl -X PURGE --header"X-Authorization: AQIC5wM2LY4SfcwJgt8XkeCFGdA48S48lm8iR8kCtHZJ5Vc." http://127.0.0.1:8888/api/find/bid/20 

this is working, but if I do purge with request_uri this doesn't work

  curl -X PURGE http://127.0.0.1:8888/api/find/bid/20 

Should ngx_cache_purge always requires full key ?

Please suggest

Thanks