0
|
1
|
|
2 /*
|
|
3 * Copyright (C) Igor Sysoev
|
|
4 */
|
|
5
|
|
6
|
|
7 #ifndef _NGX_HTTP_CACHE_H_INCLUDED_
|
|
8 #define _NGX_HTTP_CACHE_H_INCLUDED_
|
|
9
|
|
10
|
|
11 #include <ngx_config.h>
|
|
12 #include <ngx_core.h>
|
|
13 #include <ngx_http.h>
|
|
14
|
|
15
|
502
|
16 #define NGX_HTTP_CACHE_MISS 1
|
588
|
17 #define NGX_HTTP_CACHE_BYPASS 2
|
|
18 #define NGX_HTTP_CACHE_EXPIRED 3
|
|
19 #define NGX_HTTP_CACHE_STALE 4
|
|
20 #define NGX_HTTP_CACHE_UPDATING 5
|
|
21 #define NGX_HTTP_CACHE_HIT 6
|
|
22 #define NGX_HTTP_CACHE_SCARCE 7
|
0
|
23
|
464
|
24 #define NGX_HTTP_CACHE_KEY_LEN 16
|
0
|
25
|
|
26
|
|
27 typedef struct {
|
464
|
28 ngx_uint_t status;
|
|
29 time_t valid;
|
|
30 } ngx_http_cache_valid_t;
|
|
31
|
|
32
|
|
33 typedef struct {
|
|
34 ngx_rbtree_node_t node;
|
|
35 ngx_queue_t queue;
|
|
36
|
|
37 u_char key[NGX_HTTP_CACHE_KEY_LEN
|
|
38 - sizeof(ngx_rbtree_key_t)];
|
|
39
|
|
40 unsigned count:20;
|
|
41 unsigned uses:10;
|
|
42 unsigned valid_msec:10;
|
|
43 unsigned error:10;
|
|
44 unsigned exists:1;
|
498
|
45 unsigned updating:1;
|
596
|
46 unsigned deleting:1;
|
|
47 /* 11 unused bits */
|
464
|
48
|
|
49 ngx_file_uniq_t uniq;
|
|
50 time_t expire;
|
|
51 time_t valid_sec;
|
|
52 size_t body_start;
|
622
|
53 off_t fs_size;
|
464
|
54 } ngx_http_file_cache_node_t;
|
|
55
|
18
|
56
|
464
|
57 struct ngx_http_cache_s {
|
|
58 ngx_file_t file;
|
|
59 ngx_array_t keys;
|
|
60 uint32_t crc32;
|
|
61 u_char key[NGX_HTTP_CACHE_KEY_LEN];
|
|
62
|
|
63 ngx_file_uniq_t uniq;
|
|
64 time_t valid_sec;
|
|
65 time_t last_modified;
|
|
66 time_t date;
|
|
67
|
|
68 size_t header_start;
|
|
69 size_t body_start;
|
|
70 off_t length;
|
622
|
71 off_t fs_size;
|
464
|
72
|
|
73 ngx_uint_t min_uses;
|
|
74 ngx_uint_t error;
|
|
75 ngx_uint_t valid_msec;
|
|
76
|
|
77 ngx_buf_t *buf;
|
|
78
|
|
79 ngx_http_file_cache_t *file_cache;
|
|
80 ngx_http_file_cache_node_t *node;
|
|
81
|
656
|
82 ngx_msec_t lock_timeout;
|
|
83 ngx_msec_t wait_time;
|
|
84
|
|
85 ngx_event_t wait_event;
|
|
86
|
|
87 unsigned lock:1;
|
|
88 unsigned waiting:1;
|
|
89
|
464
|
90 unsigned updated:1;
|
590
|
91 unsigned updating:1;
|
464
|
92 unsigned exists:1;
|
|
93 unsigned temp_file:1;
|
|
94 };
|
0
|
95
|
|
96
|
22
|
97 typedef struct {
|
464
|
98 time_t valid_sec;
|
|
99 time_t last_modified;
|
|
100 time_t date;
|
|
101 uint32_t crc32;
|
|
102 u_short valid_msec;
|
|
103 u_short header_start;
|
|
104 u_short body_start;
|
|
105 } ngx_http_file_cache_header_t;
|
26
|
106
|
|
107
|
480
|
108 typedef struct {
|
|
109 ngx_rbtree_t rbtree;
|
|
110 ngx_rbtree_node_t sentinel;
|
|
111 ngx_queue_t queue;
|
|
112 ngx_atomic_t cold;
|
514
|
113 ngx_atomic_t loading;
|
480
|
114 off_t size;
|
|
115 } ngx_http_file_cache_sh_t;
|
|
116
|
|
117
|
464
|
118 struct ngx_http_file_cache_s {
|
480
|
119 ngx_http_file_cache_sh_t *sh;
|
464
|
120 ngx_slab_pool_t *shpool;
|
18
|
121
|
464
|
122 ngx_path_t *path;
|
0
|
123
|
468
|
124 off_t max_size;
|
|
125 size_t bsize;
|
|
126
|
464
|
127 time_t inactive;
|
468
|
128
|
632
|
129 ngx_uint_t files;
|
|
130 ngx_uint_t loader_files;
|
468
|
131 ngx_msec_t last;
|
632
|
132 ngx_msec_t loader_sleep;
|
|
133 ngx_msec_t loader_threshold;
|
0
|
134
|
464
|
135 ngx_shm_zone_t *shm_zone;
|
|
136 };
|
0
|
137
|
|
138
|
588
|
139 ngx_int_t ngx_http_file_cache_new(ngx_http_request_t *r);
|
|
140 ngx_int_t ngx_http_file_cache_create(ngx_http_request_t *r);
|
464
|
141 void ngx_http_file_cache_create_key(ngx_http_request_t *r);
|
|
142 ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
|
|
143 void ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);
|
|
144 void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|
145 ngx_int_t ngx_http_cache_send(ngx_http_request_t *);
|
590
|
146 void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf);
|
464
|
147 time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status);
|
0
|
148
|
464
|
149 char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
150 void *conf);
|
|
151 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
152 void *conf);
|
18
|
153
|
572
|
154
|
502
|
155 extern ngx_str_t ngx_http_cache_status[];
|
|
156
|
0
|
157
|
|
158 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
|