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
|
|
82 unsigned updated:1;
|
590
|
83 unsigned updating:1;
|
464
|
84 unsigned exists:1;
|
|
85 unsigned temp_file:1;
|
|
86 };
|
0
|
87
|
|
88
|
22
|
89 typedef struct {
|
464
|
90 time_t valid_sec;
|
|
91 time_t last_modified;
|
|
92 time_t date;
|
|
93 uint32_t crc32;
|
|
94 u_short valid_msec;
|
|
95 u_short header_start;
|
|
96 u_short body_start;
|
|
97 } ngx_http_file_cache_header_t;
|
26
|
98
|
|
99
|
480
|
100 typedef struct {
|
|
101 ngx_rbtree_t rbtree;
|
|
102 ngx_rbtree_node_t sentinel;
|
|
103 ngx_queue_t queue;
|
|
104 ngx_atomic_t cold;
|
514
|
105 ngx_atomic_t loading;
|
480
|
106 off_t size;
|
|
107 } ngx_http_file_cache_sh_t;
|
|
108
|
|
109
|
464
|
110 struct ngx_http_file_cache_s {
|
480
|
111 ngx_http_file_cache_sh_t *sh;
|
464
|
112 ngx_slab_pool_t *shpool;
|
18
|
113
|
464
|
114 ngx_path_t *path;
|
0
|
115
|
468
|
116 off_t max_size;
|
|
117 size_t bsize;
|
|
118
|
464
|
119 time_t inactive;
|
468
|
120
|
|
121 ngx_msec_t last;
|
|
122 ngx_uint_t files;
|
0
|
123
|
464
|
124 ngx_shm_zone_t *shm_zone;
|
|
125 };
|
0
|
126
|
|
127
|
588
|
128 ngx_int_t ngx_http_file_cache_new(ngx_http_request_t *r);
|
|
129 ngx_int_t ngx_http_file_cache_create(ngx_http_request_t *r);
|
464
|
130 void ngx_http_file_cache_create_key(ngx_http_request_t *r);
|
|
131 ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
|
|
132 void ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);
|
|
133 void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|
134 ngx_int_t ngx_http_cache_send(ngx_http_request_t *);
|
590
|
135 void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf);
|
464
|
136 time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status);
|
0
|
137
|
464
|
138 char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
139 void *conf);
|
|
140 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
141 void *conf);
|
18
|
142
|
572
|
143
|
502
|
144 extern ngx_str_t ngx_http_cache_status[];
|
|
145
|
0
|
146
|
|
147 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
|