Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
93f9a2b
explain the purge logic, as clarified in FRiCKLE/ngx_cache_purge#16
dbu May 19, 2014
a22e6bd
Fix for 1.7.12 compile errors
itpp16 Apr 9, 2015
b6dace3
feat(purge all): Include option to purge all the cached files
Jun 3, 2015
d20b712
feat(partial keys): Support partial keys to purge multiple keys.
Jun 5, 2015
84f9eaa
Convert a config file to build a dynamic module
hnakamur Feb 12, 2016
da8a74c
cleanup comments a bit
itpp16 Aug 3, 2016
9077804
Update CHANGES (releng for 2.4)
denji Nov 20, 2016
e893964
added cache_purge_response_type directive, selecting a response type …
torden Feb 3, 2017
d2f6d1d
Fix compatibility with nginx-1.11.6+
Feb 2, 2017
47bb34c
Update CHANGES (releng for 2.4.1)
denji Feb 21, 2017
e2db055
Formatting code style
denji May 4, 2017
8d655ac
Travis CI: NGINX "prove t"
denji May 4, 2017
1449591
NGX_DECLINED: "404 Not Found" to "412 Precondition Failed"
denji May 8, 2017
6d0e3bf
Fix test bugs
fdintino Sep 24, 2017
86aeff7
Fix segfault in call to ngx_read_file of partial key purge
fdintino Sep 23, 2017
40c7825
Fix segfault in cplcf->conf->purge_all with separate location syntax
fdintino Sep 24, 2017
0a32010
Merge pull request #9 from fdintino/fix-tests-and-segfaults
denji Sep 25, 2017
3921e5a
Merge branch 'master' into dev/add-new-response-type
torden Sep 29, 2017
88a4aea
Merge pull request #7 from torden/dev/add-new-response-type
torden Sep 29, 2017
a3d6bc5
fixed wrong comment in README.md, change response at error (404 to 412)
torden Sep 29, 2017
3fc7e36
fixed build faile, remove path information of response body
torden Sep 29, 2017
7120fc2
fix broken characters of response body
torden Sep 29, 2017
17df38d
Merge pull request #4 from torden/dev/fix-broken-reponse-body
torden Sep 29, 2017
01af09c
added support for purging multiple pages with the same cache key
virtion Mar 25, 2020
f8fa0ad
Merge pull request #5 from virtion/master
torden May 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .astylerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# astylerc
align-pointer=name
align-reference=name
break-after-logical
#indent=spaces=2
max-code-length=120
style=google
suffix=none

# Indent
indent-preproc-block

# Padding
pad-header
unpad-paren

# Formatting:
add-brackets
#convert-tabs

# Output:
formatted
14 changes: 14 additions & 0 deletions .format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

# Search in the script folder
pushd "$(dirname $0)" >/dev/null
CWD="$(pwd -P)"
popd >/dev/null
FILES='ngx_cache_purge_module.c'

# The file format in accordance with the style defined in .astylerc
astyle -v --options='.astylerc' ${FILES} || (echo 'astyle failed'; exit 1);

# To correct this, the issuance dos2unix on each file
# sometimes adds in Windows as a string-endins (\r\n).
dos2unix --quiet ${FILES} || (echo 'dos2unix failed'; exit 2);
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.t linguist-language=Text
50 changes: 50 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
sudo: required
os: linux
dist: trusty
language: c
compiler:
- gcc
- clang
cache:
apt: true
directories:
- download-cache
env:
global:
- JOBS=4
- NGINX_VERSION=1.12.0
- NGINX_PREFIX=/opt/nginx
- OPENSSL_PREFIX=/opt/ssl
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
- OPENSSL_INC=$OPENSSL_PREFIX/include
- OPENSSL_VER=1.0.2k

before_install:
- sudo apt-get install -qq -y cpanminus

install:
- if [ ! -d /opt ]; then mkdir /opt; fi
- if [ ! -d download-cache ]; then mkdir download-cache; fi
- if [ ! -f download-cache/nginx-$NGINX_VERSION.tar.gz ]; then wget -O download-cache/nginx-$NGINX_VERSION.tar.gz http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz; fi
- if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -O download-cache/openssl-$OPENSSL_VER.tar.gz https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz; fi
- git clone https://github.com/openresty/test-nginx.git

script:
- cd test-nginx/ && sudo cpanm . && cd ..
- tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz
- cd openssl-$OPENSSL_VER/
- ./config shared --prefix=$OPENSSL_PREFIX -DPURIFY > build.log 2>&1 || (cat build.log && exit 1)
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
- sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1)
- cd ..
- tar zxf download-cache/nginx-$NGINX_VERSION.tar.gz
- cd nginx-$NGINX_VERSION/
- ./configure --prefix=$NGINX_PREFIX --with-debug --add-module=$PWD/.. > build.log 2>&1 || (cat build.log && exit 1)
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
- sudo make install > build.log 2>&1 || (cat build.log && exit 1)
- cd ..
- export PATH=$NGINX_PREFIX/sbin:$PATH
# - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH
- nginx -V
- ldd `which nginx`
- prove t
21 changes: 21 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
2017-02-21 VERSION 2.4.1
* Fix compatibility with nginx-1.11.6+, Sułowicz Paweł

2016-11-20 VERSION 2.4
* Fix compatibility with nginx-1.7.12+.
* explain the purge logic
* feat(purge all): Include option to purge all the cached files
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.
* feat(partial keys): Support partial keys to purge multiple keys.
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.
* Convert a config file to build a dynamic module

2014-12-23 VERSION 2.3
* Fix compatibility with nginx-1.7.9+.

Expand Down
126 changes: 121 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
About
=====
`ngx_cache_purge` is `nginx` module which adds ability to purge content from
`FastCGI`, `proxy`, `SCGI` and `uWSGI` caches.
`FastCGI`, `proxy`, `SCGI` and `uWSGI` caches. A purge operation removes the
content with the same cache key as the purge request has.


Sponsors
Expand All @@ -18,7 +19,7 @@ Configuration directives (same location syntax)
===============================================
fastcgi_cache_purge
-------------------
* **syntax**: `fastcgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]`
* **syntax**: `fastcgi_cache_purge on|off|<method> [purge_all] [from all|<ip> [.. <ip>]]`
* **default**: `none`
* **context**: `http`, `server`, `location`

Expand All @@ -27,7 +28,7 @@ Allow purging of selected pages from `FastCGI`'s cache.

proxy_cache_purge
-----------------
* **syntax**: `proxy_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]`
* **syntax**: `proxy_cache_purge on|off|<method> [purge_all] [from all|<ip> [.. <ip>]]`
* **default**: `none`
* **context**: `http`, `server`, `location`

Expand All @@ -36,7 +37,7 @@ Allow purging of selected pages from `proxy`'s cache.

scgi_cache_purge
----------------
* **syntax**: `scgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]`
* **syntax**: `scgi_cache_purge on|off|<method> [purge_all] [from all|<ip> [.. <ip>]]`
* **default**: `none`
* **context**: `http`, `server`, `location`

Expand All @@ -45,7 +46,7 @@ Allow purging of selected pages from `SCGI`'s cache.

uwsgi_cache_purge
-----------------
* **syntax**: `uwsgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]`
* **syntax**: `uwsgi_cache_purge on|off|<method> [purge_all] [from all|<ip> [.. <ip>]]`
* **default**: `none`
* **context**: `http`, `server`, `location`

Expand Down Expand Up @@ -89,6 +90,50 @@ uwsgi_cache_purge

Sets area and key used for purging selected pages from `uWSGI`'s cache.

Configuration directives (Optional)
===================================================

cache_purge_response_type
-----------------
* **syntax**: `cache_purge_response_type html|json|xml|text`
* **default**: `html`
* **context**: `http`, `server`, `location`

Sets a response type of purging result.



Partial Keys
============
Sometimes it's not possible to pass the exact key cache to purge a page. For example; when the content of a cookie or the params are part of the key.
You can specify a partial key adding an asterisk at the end of the URL.

curl -X PURGE /page*

The asterisk must be the last character of the key, so you **must** put the $uri variable at the end.



Purging multiple cache entries with the same cache key
======================================================
Caching requests that use the "Vary" header may result in multiple cache
entries with the same cache key. For example, when using the request header
"Vary: Accept-Encoding", a separate cache entry (with different file hash)
will be stored for each content encoding (like compressed or uncompressed),
but they will all have the exact same cache key.

Trying to purge such cached content will fail unless both the "Vary" header
is specified in the purge request, plus all headers as listed in the "Vary"
header, with the exact same values as used when the request was cached.

To be able to purge *all* pages with the same cache key, specify the key with
a "$" at the end, like this:

curl -X PURGE /page$

This will purge all content with the exact key "/page" from the cache.



Sample configuration (same location syntax)
===========================================
Expand All @@ -106,6 +151,22 @@ Sample configuration (same location syntax)
}


Sample configuration (same location syntax - purge all cached files)
====================================================================
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;
}
}
}


Sample configuration (separate location syntax)
===============================================
http {
Expand All @@ -126,6 +187,61 @@ Sample configuration (separate location syntax)
}
}

Sample configuration (Optional)
===============================================
http {
proxy_cache_path /tmp/cache keys_zone=tmpcache:10m;

cache_purge_response_type text;

server {

cache_purge_response_type json;

location / { #json
proxy_pass http://127.0.0.1:8000;
proxy_cache tmpcache;
proxy_cache_key $uri$is_args$args;
}

location ~ /purge(/.*) { #xml
allow 127.0.0.1;
deny all;
proxy_cache_purge tmpcache $1$is_args$args;
cache_purge_response_type xml;
}

location ~ /purge2(/.*) { # json
allow 127.0.0.1;
deny all;
proxy_cache_purge tmpcache $1$is_args$args;
}
}

server {

location / { #text
proxy_pass http://127.0.0.1:8000;
proxy_cache tmpcache;
proxy_cache_key $uri$is_args$args;
}

location ~ /purge(/.*) { #text
allow 127.0.0.1;
deny all;
proxy_cache_purge tmpcache $1$is_args$args;
}

location ~ /purge2(/.*) { #html
allow 127.0.0.1;
deny all;
proxy_cache_purge tmpcache $1$is_args$args;
cache_purge_response_type html;
}
}
}



Testing
=======
Expand Down
14 changes: 12 additions & 2 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@ if [ "$HTTP_UWSGI" = "YES" ]; then
fi

ngx_addon_name=ngx_http_cache_purge_module
HTTP_MODULES="$HTTP_MODULES ngx_http_cache_purge_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_cache_purge_module.c"
CACHE_PURGE_SRCS="$ngx_addon_dir/ngx_cache_purge_module.c"

if [ -n "$ngx_module_link" ]; then
ngx_module_type=HTTP
ngx_module_name="$ngx_addon_name"
ngx_module_srcs="$CACHE_PURGE_SRCS"

. auto/module
else
HTTP_MODULES="$HTTP_MODULES $ngx_addon_name"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $CACHE_PURGE_SRCS"
fi

have=NGX_CACHE_PURGE_MODULE . auto/have
Loading