Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: option to purge all the cached content #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fmbiete
Copy link

@fmbiete fmbiete commented Jun 3, 2015

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.

This option can be slow if a lot of content is cached, or if the
storage used for the cache is slow. But you really should be using
RAM as your cache storage.

Signed-off-by: Francisco Miguel Biete <[email protected]>
<[email protected]>
@huglester
Copy link

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

@hpatoio
Copy link

hpatoio commented Jun 6, 2015

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
Copy link
Author

fmbiete commented Jun 6, 2015

With that config you should use:

curl -X PURGE http://yourserver/

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

@hpatoio
Copy link

hpatoio commented Jun 8, 2015

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
Copy link
Author

fmbiete commented Jun 8, 2015

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.

@rfnx rfnx mentioned this pull request Nov 23, 2015
denji pushed a commit to nginx-modules/ngx_cache_purge that referenced this pull request Aug 3, 2016
This option can be slow if a lot of content is cached, or if the
storage used for the cache is slow. But you really should be using
RAM as your cache storage.

Signed-off-by: Francisco Miguel Biete <[email protected]>
Signed-off-by: Francisco Miguel Biete <[email protected]>

Resolved FRiCKLE#33
Resolved FRiCKLE#35
denji pushed a commit to nginx-modules/ngx_cache_purge that referenced this pull request Aug 3, 2016
Put an '*' at the end of your purge cache URL.
e.g:
    proxy_cache_key $scheme$host$uri$is_args$args$cookie_JSESSIONID;

    curl -X PURGE https://example.com/pass*

This will remove every cached page whose key cache starting with:
    httpsexample.com/pass*

Be careful not passing any value for the values after the $uri, or put
it at the end of your cache key.

Signed-off-by: Francisco Miguel Biete <[email protected]>
Signed-off-by: Francisco Miguel Biete <[email protected]>

Resolved FRiCKLE#33
Resolved FRiCKLE#35
@guilhem
Copy link

guilhem commented Jul 16, 2021

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;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants