ngx_http_file_cache_create()

This commit is contained in:
Igor Sysoev 2010-07-15 14:01:02 +00:00
parent 3f9edd109f
commit 06189be984
3 changed files with 25 additions and 9 deletions

View File

@ -121,6 +121,7 @@ struct ngx_http_file_cache_s {
};
ngx_int_t ngx_http_file_cache_create(ngx_http_request_t *r);
void ngx_http_file_cache_create_key(ngx_http_request_t *r);
ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
void ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);

View File

@ -144,6 +144,27 @@ ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data)
}
ngx_int_t
ngx_http_file_cache_create(ngx_http_request_t *r)
{
ngx_http_cache_t *c;
c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
if (c == NULL) {
return NGX_ERROR;
}
if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
return NGX_ERROR;
}
r->cache = c;
c->file.log = r->connection->log;
return NGX_OK;
}
void
ngx_http_file_cache_create_key(ngx_http_request_t *r)
{

View File

@ -646,18 +646,10 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
u->method = ngx_http_core_get_method;
}
c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t));
if (c == NULL) {
if (ngx_http_file_cache_create(r) != NGX_OK) {
return NGX_ERROR;
}
if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) {
return NGX_ERROR;
}
r->cache = c;
c->file.log = r->connection->log;
if (u->create_key(r) != NGX_OK) {
return NGX_ERROR;
}
@ -668,6 +660,8 @@ ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
u->cacheable = 1;
c = r->cache;
c->min_uses = u->conf->cache_min_uses;
c->body_start = u->conf->buffer_size;
c->file_cache = u->conf->cache->data;