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
16 /*
17 * The 3 bits allows the 7 uses before the cache entry allocation.
18 * We can use maximum 7 bits, i.e up to the 127 uses.
19 */
20 #define NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS 3
21
22
23 typedef struct {
24 uint32_t crc;
25 ngx_str_t key;
26 time_t accessed;
27
28 unsigned refs:20; /* 1048576 references */
29
30 unsigned count:NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS;
31
32 unsigned deleted:1;
33 unsigned expired:1;
34 unsigned memory:1;
35 unsigned mmap:1;
36 unsigned notify:1;
37
38 ngx_fd_t fd;
39 #if (NGX_USE_HTTP_FILE_CACHE_UNIQ)
40 ngx_file_uniq_t uniq; /* no needed with kqueue */
41 #endif
42 time_t last_modified;
43 time_t updated;
44
45 union {
46 off_t size;
47 ngx_str_t value;
48 } data;
49 } ngx_http_cache_entry_t;
50
51
52 typedef struct {
53 time_t expires;
54 time_t last_modified;
55 time_t date;
56 off_t length;
57 size_t key_len;
58 char key[1];
59 } ngx_http_cache_header_t;
60
61
62 #define NGX_HTTP_CACHE_HASH 7
63 #define NGX_HTTP_CACHE_NELTS 4
64
65 typedef struct {
66 ngx_http_cache_entry_t *elts;
67 size_t hash;
68 size_t nelts;
69 time_t life;
70 time_t update;
71 #if (NGX_THREADS)
72 ngx_mutex_t mutex;
73 #endif
74 ngx_pool_t *pool;
75 } ngx_http_cache_hash_t;
76
77
78 typedef struct {
79 ngx_http_cache_hash_t *hash;
80 ngx_http_cache_entry_t *cache;
81 ngx_file_t file;
82 ngx_array_t key;
83 uint32_t crc;
84 u_char md5[16];
85 ngx_path_t *path;
86 ngx_buf_t *buf;
87 time_t expires;
88 time_t last_modified;
89 time_t date;
90 off_t length;
91 size_t key_len;
92 size_t file_start;
93 ngx_file_uniq_t uniq;
94 ngx_log_t *log;
95
96 /* STUB */
97 ssize_t header_size;
98 ngx_str_t key0;
99 } ngx_http_cache_t;
100
101
102 typedef struct {
103 ngx_path_t *path;
104 ngx_str_t key;
105 ngx_buf_t *buf;
106
107 unsigned file:1;
108 unsigned memory:1;
109 unsigned primary:1;
110 } ngx_http_cache_ctx_t;
111
112
113 #define NGX_HTTP_CACHE_STALE 1
114 #define NGX_HTTP_CACHE_AGED 2
115 #define NGX_HTTP_CACHE_THE_SAME 3
116
117
118 ngx_int_t ngx_http_cache_get(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx);
119
120 ngx_int_t ngx_http_file_cache_get(ngx_http_request_t *r,
121 ngx_http_cache_ctx_t *ctx);
122
123 ngx_int_t ngx_http_file_cache_open(ngx_http_cache_t *c);
124
125 ngx_int_t ngx_http_cache_cleaner_handler(ngx_gc_t *gc, ngx_str_t *name,
126 ngx_dir_t *dir);
127
128
129 #if 0
130
131 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *cache,
132 ngx_http_cleanup_t *cleanup,
133 ngx_str_t *key, uint32_t *crc);
134
135 ngx_http_cache_t *ngx_http_cache_alloc(ngx_http_cache_hash_t *hash,
136 ngx_http_cache_t *cache,
137 ngx_http_cleanup_t *cleanup,
138 ngx_str_t *key, uint32_t crc,
139 ngx_str_t *value, ngx_log_t *log);
140 void ngx_http_cache_free(ngx_http_cache_t *cache,
141 ngx_str_t *key, ngx_str_t *value, ngx_log_t *log);
142 void ngx_http_cache_lock(ngx_http_cache_hash_t *hash, ngx_http_cache_t *cache);
143 void ngx_http_cache_unlock(ngx_http_cache_hash_t *hash,
144 ngx_http_cache_t *cache, ngx_log_t *log);
145
146 int ngx_http_cache_update_file(ngx_http_request_t *r,ngx_http_cache_ctx_t *ctx,
147 ngx_str_t *temp_file);
148
149 int ngx_http_send_cached(ngx_http_request_t *r);
150
151
152 char *ngx_http_set_cache_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
153
154 #endif
155
156
157 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */
158
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.