Mercurial > hg > nginx
comparison src/http/ngx_http_cache.h @ 2592:3a8a53c0c42f
a prelimiary proxy cache support
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 23 Mar 2009 13:14:51 +0000 |
parents | ad1e9ebf93bb |
children | d19979e0d980 |
comparison
equal
deleted
inserted
replaced
2591:7162ac8d564f | 2592:3a8a53c0c42f |
---|---|
11 #include <ngx_config.h> | 11 #include <ngx_config.h> |
12 #include <ngx_core.h> | 12 #include <ngx_core.h> |
13 #include <ngx_http.h> | 13 #include <ngx_http.h> |
14 | 14 |
15 | 15 |
16 /* | 16 /**/ |
17 * The 3 bits allows the 7 uses before the cache entry allocation. | 17 #define NGX_HTTP_CACHE_STALE 1 |
18 * We can use maximum 7 bits, i.e up to the 127 uses. | 18 #define NGX_HTTP_CACHE_AGED 2 |
19 */ | 19 #define NGX_HTTP_CACHE_THE_SAME 3 |
20 #define NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS 3 | 20 /**/ |
21 | |
22 #define NGX_HTTP_CACHE_KEY_LEN 16 | |
21 | 23 |
22 | 24 |
23 typedef struct { | 25 typedef struct { |
24 uint32_t crc; | 26 ngx_uint_t status; |
25 ngx_str_t key; | 27 time_t valid; |
26 time_t accessed; | 28 } ngx_http_cache_valid_t; |
27 | 29 |
28 unsigned refs:20; /* 1048576 references */ | |
29 | 30 |
30 unsigned count:NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS; | 31 /* ngx_http_file_cache_node_t takes exactly 64 bytes on FreeBSD/i386 */ |
31 | 32 |
32 unsigned deleted:1; | 33 typedef struct { |
33 unsigned expired:1; | 34 ngx_rbtree_node_t node; |
34 unsigned memory:1; | 35 ngx_queue_t queue; |
35 unsigned mmap:1; | |
36 unsigned notify:1; | |
37 | 36 |
38 ngx_fd_t fd; | 37 u_char key[NGX_HTTP_CACHE_KEY_LEN |
39 #if (NGX_USE_HTTP_FILE_CACHE_UNIQ) | 38 - sizeof(ngx_rbtree_key_t)]; |
40 ngx_file_uniq_t uniq; /* no needed with kqueue */ | |
41 #endif | |
42 time_t last_modified; | |
43 time_t updated; | |
44 | 39 |
45 union { | 40 unsigned count:20; |
46 off_t size; | 41 unsigned uses:10; |
47 ngx_str_t value; | 42 unsigned valid_msec:10; |
48 } data; | 43 unsigned error:10; |
49 } ngx_http_cache_entry_t; | 44 /* 7 unused bits */ |
45 unsigned exists:1; | |
46 | |
47 ngx_file_uniq_t uniq; | |
48 time_t expire; | |
49 time_t valid_sec; | |
50 size_t body_start; | |
51 } ngx_http_file_cache_node_t; | |
52 | |
53 | |
54 struct ngx_http_cache_s { | |
55 ngx_file_t file; | |
56 ngx_array_t keys; | |
57 uint32_t crc32; | |
58 u_char key[NGX_HTTP_CACHE_KEY_LEN]; | |
59 | |
60 ngx_file_uniq_t uniq; | |
61 time_t valid_sec; | |
62 time_t last_modified; | |
63 time_t date; | |
64 | |
65 size_t header_start; | |
66 size_t body_start; | |
67 off_t length; | |
68 | |
69 ngx_uint_t min_uses; | |
70 ngx_uint_t uses; | |
71 ngx_uint_t error; | |
72 ngx_uint_t valid_msec; | |
73 | |
74 ngx_buf_t *buf; | |
75 | |
76 ngx_http_file_cache_t *file_cache; | |
77 ngx_http_file_cache_node_t *node; | |
78 | |
79 unsigned updated:1; | |
80 unsigned exists:1; | |
81 unsigned temp_file:1; | |
82 }; | |
50 | 83 |
51 | 84 |
52 typedef struct { | 85 typedef struct { |
53 time_t expires; | 86 time_t valid_sec; |
54 time_t last_modified; | 87 time_t last_modified; |
55 time_t date; | 88 time_t date; |
56 off_t length; | 89 uint32_t crc32; |
57 size_t key_len; | 90 u_short valid_msec; |
58 char key[1]; | 91 u_short header_start; |
59 } ngx_http_cache_header_t; | 92 u_short body_start; |
93 } ngx_http_file_cache_header_t; | |
60 | 94 |
61 | 95 |
62 #define NGX_HTTP_CACHE_HASH 7 | 96 struct ngx_http_file_cache_s { |
63 #define NGX_HTTP_CACHE_NELTS 4 | 97 ngx_rbtree_t *rbtree; |
98 ngx_queue_t *queue; | |
99 ngx_slab_pool_t *shpool; | |
64 | 100 |
65 typedef struct { | 101 ngx_path_t *path; |
66 ngx_http_cache_entry_t *elts; | 102 |
67 size_t hash; | 103 time_t inactive; |
68 size_t nelts; | 104 time_t created; |
69 time_t life; | 105 time_t clean_time; |
70 time_t update; | 106 time_t next_clean_time; |
71 #if (NGX_THREADS) | 107 |
72 ngx_mutex_t mutex; | 108 ngx_shm_zone_t *shm_zone; |
73 #endif | 109 }; |
74 ngx_pool_t *pool; | |
75 } ngx_http_cache_hash_t; | |
76 | 110 |
77 | 111 |
78 typedef struct { | 112 void ngx_http_file_cache_create_key(ngx_http_request_t *r); |
79 ngx_http_cache_hash_t *hash; | 113 ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r); |
80 ngx_http_cache_entry_t *cache; | 114 void ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf); |
81 ngx_file_t file; | 115 void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf); |
82 ngx_array_t key; | 116 ngx_int_t ngx_http_cache_send(ngx_http_request_t *); |
83 uint32_t crc; | 117 void ngx_http_file_cache_free(ngx_http_request_t *r, ngx_temp_file_t *tf); |
84 u_char md5[16]; | 118 time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status); |
85 ngx_path_t *path; | |
86 ngx_buf_t *buf; | |
87 time_t expires; | |
88 time_t last_modified; | |
89 time_t date; | |
90 off_t length; | |
91 size_t key_len; | |
92 size_t file_start; | |
93 ngx_file_uniq_t uniq; | |
94 ngx_log_t *log; | |
95 | |
96 /* STUB */ | |
97 ssize_t header_size; | |
98 ngx_str_t key0; | |
99 } ngx_http_cache_t; | |
100 | 119 |
101 | 120 |
102 typedef struct { | 121 char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
103 ngx_path_t *path; | 122 void *conf); |
104 ngx_str_t key; | 123 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
105 ngx_buf_t *buf; | 124 void *conf); |
106 | |
107 unsigned file:1; | |
108 unsigned memory:1; | |
109 unsigned primary:1; | |
110 } ngx_http_cache_ctx_t; | |
111 | |
112 | |
113 #define NGX_HTTP_CACHE_STALE 1 | |
114 #define NGX_HTTP_CACHE_AGED 2 | |
115 #define NGX_HTTP_CACHE_THE_SAME 3 | |
116 | |
117 | |
118 ngx_int_t ngx_http_cache_get(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx); | |
119 | |
120 ngx_int_t ngx_http_file_cache_get(ngx_http_request_t *r, | |
121 ngx_http_cache_ctx_t *ctx); | |
122 | |
123 ngx_int_t ngx_http_file_cache_open(ngx_http_cache_t *c); | |
124 | |
125 ngx_int_t ngx_http_cache_cleaner_handler(ngx_gc_t *gc, ngx_str_t *name, | |
126 ngx_dir_t *dir); | |
127 | |
128 | |
129 #if 0 | |
130 | |
131 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *cache, | |
132 ngx_http_cleanup_t *cleanup, | |
133 ngx_str_t *key, uint32_t *crc); | |
134 | |
135 ngx_http_cache_t *ngx_http_cache_alloc(ngx_http_cache_hash_t *hash, | |
136 ngx_http_cache_t *cache, | |
137 ngx_http_cleanup_t *cleanup, | |
138 ngx_str_t *key, uint32_t crc, | |
139 ngx_str_t *value, ngx_log_t *log); | |
140 void ngx_http_cache_free(ngx_http_cache_t *cache, | |
141 ngx_str_t *key, ngx_str_t *value, ngx_log_t *log); | |
142 void ngx_http_cache_lock(ngx_http_cache_hash_t *hash, ngx_http_cache_t *cache); | |
143 void ngx_http_cache_unlock(ngx_http_cache_hash_t *hash, | |
144 ngx_http_cache_t *cache, ngx_log_t *log); | |
145 | |
146 int ngx_http_cache_update_file(ngx_http_request_t *r,ngx_http_cache_ctx_t *ctx, | |
147 ngx_str_t *temp_file); | |
148 | |
149 int ngx_http_send_cached(ngx_http_request_t *r); | |
150 | |
151 | |
152 char *ngx_http_set_cache_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
153 | |
154 #endif | |
155 | 125 |
156 | 126 |
157 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */ | 127 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */ |