Skip to content

Commit e447079

Browse files
committed
Add ability to purge content from uWSGI's cache.
1 parent 115ffb0 commit e447079

File tree

3 files changed

+124
-6
lines changed

3 files changed

+124
-6
lines changed

CHANGES

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
2010-06-08
1+
2010-06-08 VERSION 1.1
22
* Fix compatibility with nginx-0.8.40+.
33

4+
* Add ability to purge content from uWSGI's cache.
5+
46
2010-01-10 VERSION 1.0
57
* Initial module release.
68

README

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
ABOUT:
22
------
3-
ngx_cache_purge is a module which adds ability to purge content
4-
from FastCGI and proxy caches.
5-
6-
This module is rewrite of cache_purge patch, which is successfully
7-
used in production on number of high traffic sites.
3+
ngx_cache_purge is nginx module which adds ability to purge content
4+
from FastCGI, proxy and uWSGI caches.
85

96

107
SPONSORS:
@@ -23,6 +20,10 @@ CONFIGURATION DIRECTIVES:
2320
---------------------------------------------------
2421
Sets area and key used for purging selected pages from proxy's cache.
2522

23+
uwsgi_cache_purge zone_name key (context: location)
24+
---------------------------------------------------
25+
Sets area and key used for purging selected pages from uWSGI's cache.
26+
2627

2728
EXAMPLE CONFIGURATION:
2829
----------------------

ngx_cache_purge_module.c

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ char *ngx_http_fastcgi_cache_purge_conf(ngx_conf_t *cf,
3737
ngx_command_t *cmd, void *conf);
3838
char *ngx_http_proxy_cache_purge_conf(ngx_conf_t *cf,
3939
ngx_command_t *cmd, void *conf);
40+
#if defined(nginx_version) && (nginx_version >= 8040)
41+
char *ngx_http_uwsgi_cache_purge_conf(ngx_conf_t *cf,
42+
ngx_command_t *cmd, void *conf);
43+
#endif
4044

4145
ngx_int_t ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r);
4246
ngx_int_t ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r);
47+
#if defined(nginx_version) && (nginx_version >= 8040)
48+
ngx_int_t ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r);
49+
#endif
4350

4451
ngx_int_t ngx_http_cache_purge_handler(ngx_http_request_t *r,
4552
ngx_http_file_cache_t *cache, ngx_http_complex_value_t *cache_key);
@@ -63,6 +70,15 @@ static ngx_command_t ngx_http_cache_purge_module_commands[] = {
6370
0,
6471
NULL },
6572

73+
#if defined(nginx_version) && (nginx_version >= 8040)
74+
{ ngx_string("uwsgi_cache_purge"),
75+
NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2,
76+
ngx_http_uwsgi_cache_purge_conf,
77+
NGX_HTTP_LOC_CONF_OFFSET,
78+
0,
79+
NULL },
80+
#endif
81+
6682
ngx_null_command
6783
};
6884

@@ -111,6 +127,9 @@ CRLF "</center>" CRLF
111127

112128
extern ngx_module_t ngx_http_fastcgi_module;
113129
extern ngx_module_t ngx_http_proxy_module;
130+
#if defined(nginx_version) && (nginx_version >= 8040)
131+
extern ngx_module_t ngx_http_uwsgi_module;
132+
#endif
114133

115134
/* this is ugly workaround, find better solution... */
116135
typedef struct {
@@ -183,6 +202,30 @@ typedef struct {
183202
ngx_uint_t headers_hash_max_size;
184203
ngx_uint_t headers_hash_bucket_size;
185204
} ngx_http_proxy_loc_conf_t;
205+
206+
#if defined(nginx_version) && (nginx_version >= 8040)
207+
typedef struct {
208+
ngx_http_upstream_conf_t upstream;
209+
210+
ngx_array_t *flushes;
211+
ngx_array_t *params_len;
212+
ngx_array_t *params;
213+
ngx_array_t *params_source;
214+
215+
ngx_hash_t headers_hash;
216+
ngx_uint_t header_params;
217+
218+
ngx_array_t *uwsgi_lengths;
219+
ngx_array_t *uwsgi_values;
220+
221+
ngx_http_complex_value_t cache_key;
222+
223+
ngx_str_t uwsgi_string;
224+
225+
ngx_uint_t modifier1;
226+
ngx_uint_t modifier2;
227+
} ngx_http_uwsgi_loc_conf_t;
228+
#endif
186229
/* end of ugly workaround */
187230

188231
char *
@@ -292,6 +335,61 @@ ngx_http_proxy_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
292335
return NGX_CONF_OK;
293336
}
294337

338+
#if defined(nginx_version) && (nginx_version >= 8040)
339+
char *
340+
ngx_http_uwsgi_cache_purge_conf(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
341+
{
342+
ngx_http_compile_complex_value_t ccv;
343+
ngx_http_core_loc_conf_t *clcf;
344+
ngx_http_uwsgi_loc_conf_t *ulcf;
345+
ngx_str_t *value;
346+
347+
ulcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_uwsgi_module);
348+
349+
/* check for duplicates / collisions */
350+
if (ulcf->upstream.cache != NGX_CONF_UNSET_PTR
351+
&& ulcf->upstream.cache != NULL)
352+
{
353+
return "is either duplicate or collides with \"uwsgi_cache\"";
354+
}
355+
356+
if (ulcf->upstream.upstream || ulcf->uwsgi_lengths) {
357+
return "is incompatible with \"uwsgi_pass\"";
358+
}
359+
360+
if (ulcf->upstream.store > 0 || ulcf->upstream.store_lengths) {
361+
return "is incompatible with \"uwsgi_store\"";
362+
}
363+
364+
value = cf->args->elts;
365+
366+
/* set uwsgi_cache part */
367+
ulcf->upstream.cache = ngx_shared_memory_add(cf, &value[1], 0,
368+
&ngx_http_uwsgi_module);
369+
if (ulcf->upstream.cache == NULL) {
370+
return NGX_CONF_ERROR;
371+
}
372+
373+
/* set uwsgi_cache_key part */
374+
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
375+
376+
ccv.cf = cf;
377+
ccv.value = &value[2];
378+
ccv.complex_value = &ulcf->cache_key;
379+
380+
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
381+
return NGX_CONF_ERROR;
382+
}
383+
384+
/* set handler */
385+
clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
386+
387+
clcf->handler = ngx_http_uwsgi_cache_purge_handler;
388+
389+
return NGX_CONF_OK;
390+
}
391+
#endif
392+
295393
ngx_int_t
296394
ngx_http_fastcgi_cache_purge_handler(ngx_http_request_t *r)
297395
{
@@ -322,6 +420,23 @@ ngx_http_proxy_cache_purge_handler(ngx_http_request_t *r)
322420
&plcf->cache_key);
323421
}
324422

423+
#if defined(nginx_version) && (nginx_version >= 8040)
424+
ngx_int_t
425+
ngx_http_uwsgi_cache_purge_handler(ngx_http_request_t *r)
426+
{
427+
ngx_http_uwsgi_loc_conf_t *ulcf;
428+
429+
if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD|NGX_HTTP_DELETE))) {
430+
return NGX_HTTP_NOT_ALLOWED;
431+
}
432+
433+
ulcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module);
434+
435+
return ngx_http_cache_purge_handler(r, ulcf->upstream.cache->data,
436+
&ulcf->cache_key);
437+
}
438+
#endif
439+
325440
ngx_int_t
326441
ngx_http_cache_purge_handler(ngx_http_request_t *r,
327442
ngx_http_file_cache_t *cache, ngx_http_complex_value_t *cache_key)

0 commit comments

Comments
 (0)