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