diff --git a/src/ngx_http_srcache_store.c b/src/ngx_http_srcache_store.c index 7a72115..b917368 100644 --- a/src/ngx_http_srcache_store.c +++ b/src/ngx_http_srcache_store.c @@ -253,6 +253,7 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in) { ngx_http_srcache_ctx_t *ctx, *pr_ctx; ngx_int_t rc; + ngx_str_t skip; ngx_chain_t *cl; ngx_http_srcache_loc_conf_t *slcf; size_t len; @@ -449,6 +450,19 @@ ngx_http_srcache_body_filter(ngx_http_request_t *r, ngx_chain_t *in) } #endif + if (slcf->store_skip != NULL + && ngx_http_complex_value(r, slcf->store_skip, &skip) == NGX_OK + && skip.len + && (skip.len != 1 || skip.data[0] != '0')) + { + ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, + "srcache_store skipped due to the true value in " + "srcache_store_skip: \"%V\"", &skip); + + ctx->store_response = 0; + goto done; + } + rc = ngx_http_srcache_store_subrequest(r, ctx); if (rc != NGX_OK) { diff --git a/t/store-skip.t b/t/store-skip.t index 750b56e..e802972 100644 --- a/t/store-skip.t +++ b/t/store-skip.t @@ -5,7 +5,7 @@ use Test::Nginx::Socket; #repeat_each(2); -plan tests => repeat_each() * (2 * blocks() + 6); +plan tests => repeat_each() * (2 * blocks() + 8); $ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211; @@ -371,3 +371,65 @@ Content-Length: 13 --- response_body hello, world + + +=== TEST 20: flush all +--- config + location /flush { + set $memc_cmd 'flush_all'; + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; + } +--- request +GET /flush +--- response_body eval: "OK\r\n" + + + +=== TEST 21: store_skip is true in the last minute +--- config + location /foo { + default_type text/css; + srcache_store PUT /memc $uri; + set $skip ''; + srcache_store_skip $skip; + + content_by_lua ' + ngx.say("hello") + ngx.say("world") + ngx.var.skip = 1 + '; + add_header X-Store-Status $srcache_store_status; + } + + location /memc { + internal; + + set $memc_cmd set; + set $memc_key key; + set $memc_exptime 300; + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; + } +--- request + GET /foo +--- response_body +hello +world +--- response_headers +X-Store-Status: STORE +--- error_log +srcache_store skipped due to the true value in srcache_store_skip: "1" + + + +=== TEST 22: check if /memc was invoked +--- config + location /memc { + set $memc_cmd get; + set $memc_key key; + memc_pass 127.0.0.1:$TEST_NGINX_MEMCACHED_PORT; + } +--- request + GET /memc +--- response_body_like: 404 Not Found +--- error_code: 404 +