FRiCKLE / ngx_cache_purge

nginx module which adds ability to purge content from FastCGI, proxy, SCGI and uWSGI caches.
http://labs.frickle.com/nginx_ngx_cache_purge/
Other
1.06k stars 310 forks source link

Feature: option to purge all the cached content #33

Open fmbiete opened 9 years ago

fmbiete commented 9 years ago

This adds an optional option (purge_all) to the purge_cache configuration, so if this special location is called the whole cache will be cleared.

I'm new to nginx development, and the documentation is zero, so I'm sure there is a better solution. If you can improve it, suggestions/reviews are very welcomed.

huglester commented 9 years ago

This is indeed good addition! We currently just rm -fr the cache directory...

hpatoio commented 9 years ago

This feature is interesting but I don understand the setup:

With these conf

http {
    proxy_cache_path  /tmp/cache  keys_zone=tmpcache:10m;

    server {
        location / {
            proxy_pass         http://127.0.0.1:8000;
            proxy_cache        tmpcache;
            proxy_cache_key    $uri$is_args$args;
            proxy_cache_purge  PURGE purge_all from 127.0.0.1;
        }
    }
}

Which URL you have to call to purge the whole cache ?

fmbiete commented 9 years ago

With that config you should use:

curl -X PURGE http://yourserver/

You can check the examples in the t/proxy3.t file

hpatoio commented 9 years ago

So is the very same I should use to purge the homepage right ?

IMHO you should work in another way (didn't check the conf but I hope the idea is clear)

http {
    proxy_cache_path  /tmp/cache  keys_zone=tmpcache:10m;

    server {
        location / {
            proxy_pass         http://127.0.0.1:8000;
            proxy_cache        tmpcache;
            proxy_cache_key    $uri$is_args$args;
            proxy_cache_purge  PURGE from 127.0.0.1;
        }

    server {
        location = /location_it_doesnt_exist_on_my_site {
            proxy_pass         http://127.0.0.1:8000;
            proxy_cache        tmpcache;
            proxy_cache_key    $uri$is_args$args;
            proxy_cache_purge  PURGE purge_all from 127.0.0.1;
        }

    }
}

So to purge one of you application URL use

curl -X PURGE http://yourserver/whatever/application/url.html

to purge all the cache

curl -X PURGE http://yourserver/location_it_doesnt_exist_on_my_site

Does it make sense ?

fmbiete commented 9 years ago

Of course, a "real" configuration should look like your example: existing location to purge individual pages, alternative non-existent location to purge_all, and another to purge using wildcards.

The code accepts both of them; since it's a matter of configuration it is up the user to choose what they prefer to do.

guilhem commented 3 years ago

I think a separated directory option fastcgi_cache_purge_all would be cleaner to use:

* **syntax**: `fastcgi_cache_purge_all zone_name`
* **default**: `none`
* **context**: `location`

usage:

server {
  location = /purge_all {
    proxy_cache_purge_all tmpcache;
  }
}