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
|
464
|
16 #define NGX_HTTP_CACHE_STALE 1
|
498
|
17 #define NGX_HTTP_CACHE_UPDATING 2
|
0
|
18
|
464
|
19 #define NGX_HTTP_CACHE_KEY_LEN 16
|
0
|
20
|
|
21
|
|
22 typedef struct {
|
464
|
23 ngx_uint_t status;
|
|
24 time_t valid;
|
|
25 } ngx_http_cache_valid_t;
|
|
26
|
|
27
|
|
28 typedef struct {
|
|
29 ngx_rbtree_node_t node;
|
|
30 ngx_queue_t queue;
|
|
31
|
|
32 u_char key[NGX_HTTP_CACHE_KEY_LEN
|
|
33 - sizeof(ngx_rbtree_key_t)];
|
|
34
|
|
35 unsigned count:20;
|
|
36 unsigned uses:10;
|
|
37 unsigned valid_msec:10;
|
|
38 unsigned error:10;
|
|
39 unsigned exists:1;
|
498
|
40 unsigned updating:1;
|
|
41 /* 12 unused bits */
|
464
|
42
|
|
43 ngx_file_uniq_t uniq;
|
|
44 time_t expire;
|
|
45 time_t valid_sec;
|
|
46 size_t body_start;
|
468
|
47 off_t length;
|
464
|
48 } ngx_http_file_cache_node_t;
|
|
49
|
18
|
50
|
464
|
51 struct ngx_http_cache_s {
|
|
52 ngx_file_t file;
|
|
53 ngx_array_t keys;
|
|
54 uint32_t crc32;
|
|
55 u_char key[NGX_HTTP_CACHE_KEY_LEN];
|
|
56
|
|
57 ngx_file_uniq_t uniq;
|
|
58 time_t valid_sec;
|
|
59 time_t last_modified;
|
|
60 time_t date;
|
|
61
|
|
62 size_t header_start;
|
|
63 size_t body_start;
|
|
64 off_t length;
|
|
65
|
|
66 ngx_uint_t min_uses;
|
|
67 ngx_uint_t error;
|
|
68 ngx_uint_t valid_msec;
|
|
69
|
|
70 ngx_buf_t *buf;
|
|
71
|
|
72 ngx_http_file_cache_t *file_cache;
|
|
73 ngx_http_file_cache_node_t *node;
|
|
74
|
|
75 unsigned updated:1;
|
|
76 unsigned exists:1;
|
|
77 unsigned temp_file:1;
|
|
78 };
|
0
|
79
|
|
80
|
22
|
81 typedef struct {
|
464
|
82 time_t valid_sec;
|
|
83 time_t last_modified;
|
|
84 time_t date;
|
|
85 uint32_t crc32;
|
|
86 u_short valid_msec;
|
|
87 u_short header_start;
|
|
88 u_short body_start;
|
|
89 } ngx_http_file_cache_header_t;
|
26
|
90
|
|
91
|
480
|
92 typedef struct {
|
|
93 ngx_rbtree_t rbtree;
|
|
94 ngx_rbtree_node_t sentinel;
|
|
95 ngx_queue_t queue;
|
|
96 ngx_atomic_t cold;
|
|
97 off_t size;
|
|
98 } ngx_http_file_cache_sh_t;
|
|
99
|
|
100
|
464
|
101 struct ngx_http_file_cache_s {
|
480
|
102 ngx_http_file_cache_sh_t *sh;
|
464
|
103 ngx_slab_pool_t *shpool;
|
18
|
104
|
464
|
105 ngx_path_t *path;
|
0
|
106
|
468
|
107 off_t max_size;
|
|
108 size_t bsize;
|
|
109
|
464
|
110 time_t inactive;
|
468
|
111
|
|
112 ngx_msec_t last;
|
|
113 ngx_uint_t files;
|
0
|
114
|
464
|
115 ngx_shm_zone_t *shm_zone;
|
|
116 };
|
0
|
117
|
|
118
|
464
|
119 void ngx_http_file_cache_create_key(ngx_http_request_t *r);
|
|
120 ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
|
|
121 void ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);
|
|
122 void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|
123 ngx_int_t ngx_http_cache_send(ngx_http_request_t *);
|
|
124 void ngx_http_file_cache_free(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|
125 time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status);
|
0
|
126
|
464
|
127
|
|
128 char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
129 void *conf);
|
|
130 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
131 void *conf);
|
18
|
132
|
0
|
133
|
|
134 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
|