11About
22=====
33` ngx_cache_purge ` is ` nginx ` module which adds ability to purge content from
4- ` FastCGI ` , ` proxy ` , ` SCGI ` and ` uWSGI ` caches.
4+ ` FastCGI ` , ` proxy ` , ` SCGI ` and ` uWSGI ` caches. A purge operation removes the
5+ content with the same cache key as the purge request has.
56
67
78Sponsors
@@ -18,7 +19,7 @@ Configuration directives (same location syntax)
1819===============================================
1920fastcgi_cache_purge
2021-------------------
21- * ** syntax** : ` fastcgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]] `
22+ * ** syntax** : ` fastcgi_cache_purge on|off|<method> [purge_all] [ from all|<ip> [.. <ip>]] `
2223* ** default** : ` none `
2324* ** context** : ` http ` , ` server ` , ` location `
2425
@@ -27,7 +28,7 @@ Allow purging of selected pages from `FastCGI`'s cache.
2728
2829proxy_cache_purge
2930-----------------
30- * ** syntax** : ` proxy_cache_purge on|off|<method> [from all|<ip> [.. <ip>]] `
31+ * ** syntax** : ` proxy_cache_purge on|off|<method> [purge_all] [ from all|<ip> [.. <ip>]] `
3132* ** default** : ` none `
3233* ** context** : ` http ` , ` server ` , ` location `
3334
@@ -36,7 +37,7 @@ Allow purging of selected pages from `proxy`'s cache.
3637
3738scgi_cache_purge
3839----------------
39- * ** syntax** : ` scgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]] `
40+ * ** syntax** : ` scgi_cache_purge on|off|<method> [purge_all] [ from all|<ip> [.. <ip>]] `
4041* ** default** : ` none `
4142* ** context** : ` http ` , ` server ` , ` location `
4243
@@ -45,7 +46,7 @@ Allow purging of selected pages from `SCGI`'s cache.
4546
4647uwsgi_cache_purge
4748-----------------
48- * ** syntax** : ` uwsgi_cache_purge on|off|<method> [from all|<ip> [.. <ip>]] `
49+ * ** syntax** : ` uwsgi_cache_purge on|off|<method> [purge_all] [ from all|<ip> [.. <ip>]] `
4950* ** default** : ` none `
5051* ** context** : ` http ` , ` server ` , ` location `
5152
@@ -89,6 +90,29 @@ uwsgi_cache_purge
8990
9091Sets area and key used for purging selected pages from ` uWSGI ` 's cache.
9192
93+ Configuration directives (Optional)
94+ ===================================================
95+
96+ cache_purge_response_type
97+ -----------------
98+ * ** syntax** : ` cache_purge_response_type html|json|xml|text `
99+ * ** default** : ` html `
100+ * ** context** : ` http ` , ` server ` , ` location `
101+
102+ Sets a response type of purging result.
103+
104+
105+
106+ Partial Keys
107+ ============
108+ 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.
109+ You can specify a partial key adding an asterisk at the end of the URL.
110+
111+ curl -X PURGE /page*
112+
113+ The asterisk must be the last character of the key, so you ** must** put the $uri variable at the end.
114+
115+
92116
93117Sample configuration (same location syntax)
94118===========================================
@@ -106,6 +130,22 @@ Sample configuration (same location syntax)
106130 }
107131
108132
133+ Sample configuration (same location syntax - purge all cached files)
134+ ====================================================================
135+ http {
136+ proxy_cache_path /tmp/cache keys_zone=tmpcache:10m;
137+
138+ server {
139+ location / {
140+ proxy_pass http://127.0.0.1:8000;
141+ proxy_cache tmpcache;
142+ proxy_cache_key $uri$is_args$args;
143+ proxy_cache_purge PURGE purge_all from 127.0.0.1;
144+ }
145+ }
146+ }
147+
148+
109149Sample configuration (separate location syntax)
110150===============================================
111151 http {
@@ -126,6 +166,61 @@ Sample configuration (separate location syntax)
126166 }
127167 }
128168
169+ Sample configuration (Optional)
170+ ===============================================
171+ http {
172+ proxy_cache_path /tmp/cache keys_zone=tmpcache:10m;
173+
174+ cache_purge_response_type text;
175+
176+ server {
177+
178+ cache_purge_response_type json;
179+
180+ location / { #json
181+ proxy_pass http://127.0.0.1:8000;
182+ proxy_cache tmpcache;
183+ proxy_cache_key $uri$is_args$args;
184+ }
185+
186+ location ~ /purge(/.*) { #xml
187+ allow 127.0.0.1;
188+ deny all;
189+ proxy_cache_purge tmpcache $1$is_args$args;
190+ cache_purge_response_type xml;
191+ }
192+
193+ location ~ /purge2(/.*) { # json
194+ allow 127.0.0.1;
195+ deny all;
196+ proxy_cache_purge tmpcache $1$is_args$args;
197+ }
198+ }
199+
200+ server {
201+
202+ location / { #text
203+ proxy_pass http://127.0.0.1:8000;
204+ proxy_cache tmpcache;
205+ proxy_cache_key $uri$is_args$args;
206+ }
207+
208+ location ~ /purge(/.*) { #text
209+ allow 127.0.0.1;
210+ deny all;
211+ proxy_cache_purge tmpcache $1$is_args$args;
212+ }
213+
214+ location ~ /purge2(/.*) { #html
215+ allow 127.0.0.1;
216+ deny all;
217+ proxy_cache_purge tmpcache $1$is_args$args;
218+ cache_purge_response_type html;
219+ }
220+ }
221+ }
222+
223+
129224
130225Testing
131226=======
0 commit comments