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 /**/
|
|
17 #define NGX_HTTP_CACHE_STALE 1
|
|
18 #define NGX_HTTP_CACHE_AGED 2
|
|
19 #define NGX_HTTP_CACHE_THE_SAME 3
|
|
20 /**/
|
0
|
21
|
464
|
22 #define NGX_HTTP_CACHE_KEY_LEN 16
|
0
|
23
|
|
24
|
|
25 typedef struct {
|
464
|
26 ngx_uint_t status;
|
|
27 time_t valid;
|
|
28 } ngx_http_cache_valid_t;
|
|
29
|
|
30
|
|
31 /* ngx_http_file_cache_node_t takes exactly 64 bytes on FreeBSD/i386 */
|
|
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 /* 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
|
18
|
53
|
464
|
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 };
|
0
|
83
|
|
84
|
22
|
85 typedef struct {
|
464
|
86 time_t valid_sec;
|
|
87 time_t last_modified;
|
|
88 time_t date;
|
|
89 uint32_t crc32;
|
|
90 u_short valid_msec;
|
|
91 u_short header_start;
|
|
92 u_short body_start;
|
|
93 } ngx_http_file_cache_header_t;
|
26
|
94
|
|
95
|
464
|
96 struct ngx_http_file_cache_s {
|
|
97 ngx_rbtree_t *rbtree;
|
|
98 ngx_queue_t *queue;
|
|
99 ngx_slab_pool_t *shpool;
|
18
|
100
|
464
|
101 ngx_path_t *path;
|
0
|
102
|
464
|
103 time_t inactive;
|
|
104 time_t created;
|
|
105 time_t clean_time;
|
|
106 time_t next_clean_time;
|
0
|
107
|
464
|
108 ngx_shm_zone_t *shm_zone;
|
|
109 };
|
0
|
110
|
|
111
|
464
|
112 void ngx_http_file_cache_create_key(ngx_http_request_t *r);
|
|
113 ngx_int_t ngx_http_file_cache_open(ngx_http_request_t *r);
|
|
114 void ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf);
|
|
115 void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|
116 ngx_int_t ngx_http_cache_send(ngx_http_request_t *);
|
|
117 void ngx_http_file_cache_free(ngx_http_request_t *r, ngx_temp_file_t *tf);
|
|
118 time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status);
|
0
|
119
|
464
|
120
|
|
121 char *ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
122 void *conf);
|
|
123 char *ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
|
|
124 void *conf);
|
18
|
125
|
0
|
126
|
|
127 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
|