comparison src/http/ngx_http_cache.c @ 477:ad1e9ebf93bb release-0.1.13

nginx-0.1.13-RELEASE import *) Feature: the server_names_hash and server_names_hash_threshold directives. *) Bugfix: the *.domain.tld names in the "server_name" directive did not work. *) Bugfix: the %request_length log parameter logged the incorrect length.
author Igor Sysoev <igor@sysoev.ru>
date Tue, 21 Dec 2004 12:30:30 +0000
parents 2ff194b74f1e
children
comparison
equal deleted inserted replaced
476:7e8b84ab09e9 477:ad1e9ebf93bb
7 #include <ngx_config.h> 7 #include <ngx_config.h>
8 #include <ngx_core.h> 8 #include <ngx_core.h>
9 #include <ngx_http.h> 9 #include <ngx_http.h>
10 10
11 11
12 #if 0
12 13
13 static ngx_http_module_t ngx_http_cache_module_ctx = { 14 static ngx_http_module_t ngx_http_cache_module_ctx = {
14 NULL, /* pre conf */ 15 NULL, /* pre conf */
15 16
16 NULL, /* create main configuration */ 17 NULL, /* create main configuration */
28 NGX_MODULE, 29 NGX_MODULE,
29 &ngx_http_cache_module_ctx, /* module context */ 30 &ngx_http_cache_module_ctx, /* module context */
30 NULL, /* module directives */ 31 NULL, /* module directives */
31 NGX_HTTP_MODULE, /* module type */ 32 NGX_HTTP_MODULE, /* module type */
32 NULL, /* init module */ 33 NULL, /* init module */
33 NULL /* init child */ 34 NULL /* init process */
34 }; 35 };
36
37 #endif
38
39
40 static ngx_int_t ngx_http_cache_create(ngx_http_request_t *r)
41 {
42 ngx_str_t *key;
43
44 if (!(r->cache = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t)))) {
45 return NGX_ERROR;
46 }
47
48 if (ngx_array_init(&r->cache->key, r->pool, 5, sizeof(ngx_str_t))
49 == NGX_ERROR)
50 {
51 return NGX_ERROR;
52 }
53
54 /* preallocate the primary key */
55
56 if (!(key = ngx_array_push(&r->cache->key))) {
57 return NGX_ERROR;
58 }
59
60 key->len = 0;
61 key->data = NULL;
62
63 /*
64 * we use offsetof() because sizeof() pads the struct size to the int size
65 */
66
67 r->cache->header_size = offsetof(ngx_http_cache_header_t, key);
68
69 r->cache->log = r->connection->log;
70 r->cache->file.log = r->connection->log;
71
72 return NGX_OK;
73 }
74
75
76 ngx_int_t ngx_http_cache_get(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx)
77 {
78 ngx_str_t *key;
79 ngx_http_cache_t *c;
80
81 if (r->cache == NULL) {
82 if (ngx_http_cache_create(r) == NGX_ERROR) {
83 return NGX_ABORT;
84 }
85 }
86
87 c = r->cache;
88 key = c->key.elts;
89
90 if (ctx->primary) {
91 key[0] = ctx->key;
92 c->header_size += ctx->key.len;
93 c->key_len += ctx->key.len;
94 c->buf = ctx->buf;
95
96 } else {
97 if (key[0].len == 0) {
98 key[0] = r->uri;
99 c->header_size += r->uri.len;
100 c->key_len += ctx->key.len;
101 }
102
103 if (!(key = ngx_array_push(&r->cache->key))) {
104 return NGX_ABORT;
105 }
106
107 c->header_size += ctx->key.len;
108 c->key_len += ctx->key.len;
109 }
110
111 #if 0
112
113 if (ctx->memory) {
114 ngx_http_memory_cache_get(r, ctx);
115 }
116
117 #endif
118
119 if (ctx->file) {
120 return ngx_http_file_cache_get(r, ctx);
121 }
122
123 return NGX_DECLINED;
124 }
125
126
127 #if 0
35 128
36 129
37 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *hash, 130 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *hash,
38 ngx_http_cleanup_t *cleanup, 131 ngx_http_cleanup_t *cleanup,
39 ngx_str_t *key, uint32_t *crc) 132 ngx_str_t *key, uint32_t *crc)
476 } 569 }
477 } 570 }
478 571
479 return NGX_CONF_OK; 572 return NGX_CONF_OK;
480 } 573 }
574
575
576 #endif