proxy_cache_key

This commit is contained in:
Igor Sysoev 2009-04-06 08:58:44 +00:00
parent 43f3f4a73d
commit 44a69c83a4

View File

@ -64,6 +64,10 @@ typedef struct {
ngx_str_t location; ngx_str_t location;
ngx_str_t url; ngx_str_t url;
#if (NGX_HTTP_CACHE)
ngx_http_complex_value_t cache_key;
#endif
ngx_http_proxy_vars_t vars; ngx_http_proxy_vars_t vars;
ngx_flag_t redirect; ngx_flag_t redirect;
@ -132,6 +136,8 @@ static char *ngx_http_proxy_store(ngx_conf_t *cf, ngx_command_t *cmd,
#if (NGX_HTTP_CACHE) #if (NGX_HTTP_CACHE)
static char *ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd, static char *ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf); void *conf);
static char *ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf);
#endif #endif
static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data); static char *ngx_http_proxy_lowat_check(ngx_conf_t *cf, void *post, void *data);
@ -327,6 +333,13 @@ static ngx_command_t ngx_http_proxy_commands[] = {
0, 0,
NULL }, NULL },
{ ngx_string("proxy_cache_key"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
ngx_http_proxy_cache_key,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("proxy_cache_path"), { ngx_string("proxy_cache_path"),
NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE, NGX_HTTP_MAIN_CONF|NGX_CONF_2MORE,
ngx_http_file_cache_set_slot, ngx_http_file_cache_set_slot,
@ -715,6 +728,15 @@ ngx_http_proxy_create_key(ngx_http_request_t *r)
return NGX_ERROR; return NGX_ERROR;
} }
if (plcf->cache_key.value.len) {
if (ngx_http_complex_value(r, &plcf->cache_key, key) != NGX_OK) {
return NGX_ERROR;
}
return NGX_OK;
}
*key = ctx->vars.key_start; *key = ctx->vars.key_start;
key = ngx_array_push(&r->cache->keys); key = ngx_array_push(&r->cache->keys);
@ -2068,6 +2090,10 @@ ngx_http_proxy_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
ngx_conf_merge_ptr_value(conf->upstream.cache_valid, ngx_conf_merge_ptr_value(conf->upstream.cache_valid,
prev->upstream.cache_valid, NULL); prev->upstream.cache_valid, NULL);
if (conf->cache_key.value.data == NULL) {
conf->cache_key = prev->cache_key;
}
#endif #endif
if (conf->method.len == 0) { if (conf->method.len == 0) {
@ -2738,6 +2764,34 @@ ngx_http_proxy_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_OK; return NGX_CONF_OK;
} }
static char *
ngx_http_proxy_cache_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
ngx_http_proxy_loc_conf_t *plcf = conf;
ngx_str_t *value;
ngx_http_compile_complex_value_t ccv;
value = cf->args->elts;
if (plcf->cache_key.value.len) {
return "is duplicate";
}
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
ccv.cf = cf;
ccv.value = &value[1];
ccv.complex_value = &plcf->cache_key;
if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
return NGX_CONF_ERROR;
}
return NGX_CONF_OK;
}
#endif #endif