comparison src/http/ngx_http_cache.h @ 0:f0b350454894 NGINX_0_1_0

nginx 0.1.0 *) The first public version.
author Igor Sysoev <http://sysoev.ru>
date Mon, 04 Oct 2004 00:00:00 +0400
parents
children 6f8b0dc0f8dd
comparison
equal deleted inserted replaced
-1:000000000000 0:f0b350454894
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 7 uses before an 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 typedef struct {
23 uint32_t crc;
24 ngx_str_t key;
25 time_t accessed;
26
27 unsigned refs:20; /* 1048576 references */
28
29 unsigned count:NGX_HTTP_CACHE_LAZY_ALLOCATION_BITS;
30
31 unsigned deleted:1;
32 unsigned expired:1;
33 unsigned memory:1;
34 unsigned mmap:1;
35 unsigned notify:1;
36
37 ngx_fd_t fd;
38 #if (NGX_USE_HTTP_FILE_CACHE_UNIQ)
39 ngx_file_uniq_t uniq; /* no needed with kqueue */
40 #endif
41 time_t last_modified;
42 time_t updated;
43
44 union {
45 off_t size;
46 ngx_str_t value;
47 } data;
48 } ngx_http_cache_t;
49
50
51 typedef struct {
52 time_t expires;
53 time_t last_modified;
54 time_t date;
55 off_t length;
56 size_t key_len;
57 char key[1];
58 } ngx_http_cache_header_t;
59
60
61 #define NGX_HTTP_CACHE_HASH 7
62 #define NGX_HTTP_CACHE_NELTS 4
63
64 typedef struct {
65 ngx_http_cache_t *elts;
66 size_t hash;
67 size_t nelts;
68 time_t life;
69 time_t update;
70 #if (NGX_THREADS)
71 ngx_mutex_t mutex;
72 #endif
73 ngx_pool_t *pool;
74 } ngx_http_cache_hash_t;
75
76
77 typedef struct {
78 ngx_http_cache_hash_t *hash;
79 ngx_http_cache_t *cache;
80 ngx_file_t file;
81 ngx_str_t key;
82 uint32_t crc;
83 u_char md5[16];
84 ngx_path_t *path;
85 ngx_buf_t *buf;
86 time_t expires;
87 time_t last_modified;
88 time_t date;
89 off_t length;
90 ssize_t header_size;
91 size_t file_start;
92 ngx_log_t *log;
93 } ngx_http_cache_ctx_t;
94
95
96
97 #define NGX_HTTP_CACHE_STALE 1
98 #define NGX_HTTP_CACHE_AGED 2
99 #define NGX_HTTP_CACHE_THE_SAME 3
100
101
102 ngx_http_cache_t *ngx_http_cache_get(ngx_http_cache_hash_t *cache,
103 ngx_http_cleanup_t *cleanup,
104 ngx_str_t *key, uint32_t *crc);
105
106 ngx_http_cache_t *ngx_http_cache_alloc(ngx_http_cache_hash_t *hash,
107 ngx_http_cache_t *cache,
108 ngx_http_cleanup_t *cleanup,
109 ngx_str_t *key, uint32_t crc,
110 ngx_str_t *value, ngx_log_t *log);
111 void ngx_http_cache_free(ngx_http_cache_t *cache,
112 ngx_str_t *key, ngx_str_t *value, ngx_log_t *log);
113 void ngx_http_cache_lock(ngx_http_cache_hash_t *hash, ngx_http_cache_t *cache);
114 void ngx_http_cache_unlock(ngx_http_cache_hash_t *hash,
115 ngx_http_cache_t *cache, ngx_log_t *log);
116
117 int ngx_http_cache_get_file(ngx_http_request_t *r, ngx_http_cache_ctx_t *ctx);
118 int ngx_http_cache_open_file(ngx_http_cache_ctx_t *ctx, ngx_file_uniq_t uniq);
119 int ngx_http_cache_update_file(ngx_http_request_t *r,ngx_http_cache_ctx_t *ctx,
120 ngx_str_t *temp_file);
121
122 int ngx_http_send_cached(ngx_http_request_t *r);
123
124
125 int ngx_garbage_collector_http_cache_handler(ngx_gc_t *gc, ngx_str_t *name,
126 ngx_dir_t *dir);
127
128 char *ngx_http_set_cache_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
129
130
131 #endif /* _NGX_HTTP_CACHE_H_INCLUDED_ */