Skip to content

Commit ad112da

Browse files
committed
feature: now the value specified in srcache_store_skip is checked again right before the srcache_store subrequest is issued. thanks Eldar Zaitov for the patch in openresty#25.
1 parent 39b79c2 commit ad112da

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

src/ngx_http_srcache_store.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
253253
{
254254
ngx_http_srcache_ctx_t *ctx, *pr_ctx;
255255
ngx_int_t rc;
256+
ngx_str_t skip;
256257
ngx_chain_t *cl;
257258
ngx_http_srcache_loc_conf_t *slcf;
258259
size_t len;
@@ -449,6 +450,19 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
449450
}
450451
#endif
451452

453+
if (slcf->store_skip != NULL
454+
&& ngx_http_complex_value(r, slcf->store_skip, &skip) == NGX_OK
455+
&& skip.len
456+
&& (skip.len != 1 || skip.data[0] != '0'))
457+
{
458+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
459+
"srcache_store skipped due to the true value in "
460+
"srcache_store_skip: \"%V\"", &skip);
461+
462+
ctx->store_response = 0;
463+
goto done;
464+
}
465+
452466
rc = ngx_http_srcache_store_subrequest(r, ctx);
453467

454468
if (rc != NGX_OK) {

t/store-skip.t

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test::Nginx::Socket;
55

66
#repeat_each(2);
77

8-
plan tests => repeat_each() * (2 * blocks() + 6);
8+
plan tests => repeat_each() * (2 * blocks() + 8);
99

1010
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
1111

@@ -371,3 +371,65 @@ Content-Length: 13
371371
--- response_body
372372
hello, world
373373
374+
375+
376+
=== TEST 20: flush all
377+
--- config
378+
location /flush {
379+
set $memc_cmd 'flush_all';
380+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
381+
}
382+
--- request
383+
GET /flush
384+
--- response_body eval: "OK\r\n"
385+
386+
387+
388+
=== TEST 21: store_skip is true in the last minute
389+
--- config
390+
location /foo {
391+
default_type text/css;
392+
srcache_store PUT /memc $uri;
393+
set $skip '';
394+
srcache_store_skip $skip;
395+
396+
content_by_lua '
397+
ngx.say("hello")
398+
ngx.say("world")
399+
ngx.var.skip = 1
400+
';
401+
add_header X-Store-Status $srcache_store_status;
402+
}
403+
404+
location /memc {
405+
internal;
406+
407+
set $memc_cmd set;
408+
set $memc_key key;
409+
set $memc_exptime 300;
410+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
411+
}
412+
--- request
413+
GET /foo
414+
--- response_body
415+
hello
416+
world
417+
--- response_headers
418+
X-Store-Status: STORE
419+
--- error_log
420+
srcache_store skipped due to the true value in srcache_store_skip: "1"
421+
422+
423+
424+
=== TEST 22: check if /memc was invoked
425+
--- config
426+
location /memc {
427+
set $memc_cmd get;
428+
set $memc_key key;
429+
memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT;
430+
}
431+
--- request
432+
GET /memc
433+
--- response_body_like: 404 Not Found
434+
--- error_code: 404
435+

0 commit comments

Comments
 (0)