Mercurial > hg > nginx
annotate src/http/ngx_http_file_cache.c @ 6403:e59e617f8fcb
Configure: fixed static nginx build with OpenSSL (ticket #903).
Before 7142b04337d6, it was possible to build the OpenSSL library
along with nginx, and link nginx statically with this library
(--with-openssl=DIR --with-ld-opt=-static --with-http_ssl_module).
This was broken on Linux by not adding -ldl after -lcrypto.
The fix also makes it possible to link nginx statically on Linux
with the system OpenSSL library, which never worked before.
author | Ruslan Ermilov <ru@nginx.com> |
---|---|
date | Thu, 18 Feb 2016 11:39:57 +0300 |
parents | 4821fc788c12 |
children | 9fd738b85fad |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
265
diff
changeset
|
6 |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_http.h> |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
11 #include <ngx_md5.h> |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
14 static ngx_int_t ngx_http_file_cache_lock(ngx_http_request_t *r, |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
15 ngx_http_cache_t *c); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
16 static void ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev); |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
17 static void ngx_http_file_cache_lock_wait(ngx_http_request_t *r, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
18 ngx_http_cache_t *c); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
19 static ngx_int_t ngx_http_file_cache_read(ngx_http_request_t *r, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
20 ngx_http_cache_t *c); |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
21 static ssize_t ngx_http_file_cache_aio_read(ngx_http_request_t *r, |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
22 ngx_http_cache_t *c); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
23 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
24 static void ngx_http_cache_aio_event_handler(ngx_event_t *ev); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
25 #endif |
6063
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
26 #if (NGX_THREADS) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
27 static ngx_int_t ngx_http_cache_thread_handler(ngx_thread_task_t *task, |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
28 ngx_file_t *file); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
29 static void ngx_http_cache_thread_event_handler(ngx_event_t *ev); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
30 #endif |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
31 static ngx_int_t ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
32 ngx_http_cache_t *c); |
3696 | 33 static ngx_int_t ngx_http_file_cache_name(ngx_http_request_t *r, |
34 ngx_path_t *path); | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
35 static ngx_http_file_cache_node_t * |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
36 ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
37 static void ngx_http_file_cache_rbtree_insert_value(ngx_rbtree_node_t *temp, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
38 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel); |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
39 static void ngx_http_file_cache_vary(ngx_http_request_t *r, u_char *vary, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
40 size_t len, u_char *hash); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
41 static void ngx_http_file_cache_vary_header(ngx_http_request_t *r, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
42 ngx_md5_t *md5, ngx_str_t *name); |
5880
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
43 static ngx_int_t ngx_http_file_cache_reopen(ngx_http_request_t *r, |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
44 ngx_http_cache_t *c); |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
45 static ngx_int_t ngx_http_file_cache_update_variant(ngx_http_request_t *r, |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
46 ngx_http_cache_t *c); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
47 static void ngx_http_file_cache_cleanup(void *data); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
48 static time_t ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
49 static time_t ngx_http_file_cache_expire(ngx_http_file_cache_t *cache); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
50 static void ngx_http_file_cache_delete(ngx_http_file_cache_t *cache, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
51 ngx_queue_t *q, u_char *name); |
4018
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
52 static void ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
53 static ngx_int_t ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
54 ngx_str_t *path); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
55 static ngx_int_t ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
56 ngx_str_t *path); |
5968
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
57 static ngx_int_t ngx_http_file_cache_manage_directory(ngx_tree_ctx_t *ctx, |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
58 ngx_str_t *path); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
59 static ngx_int_t ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
60 ngx_str_t *path); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
61 static ngx_int_t ngx_http_file_cache_add(ngx_http_file_cache_t *cache, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
62 ngx_http_cache_t *c); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
63 static ngx_int_t ngx_http_file_cache_delete_file(ngx_tree_ctx_t *ctx, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
64 ngx_str_t *path); |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
65 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
66 |
2952 | 67 ngx_str_t ngx_http_cache_status[] = { |
68 ngx_string("MISS"), | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
69 ngx_string("BYPASS"), |
2952 | 70 ngx_string("EXPIRED"), |
71 ngx_string("STALE"), | |
72 ngx_string("UPDATING"), | |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
73 ngx_string("REVALIDATED"), |
2952 | 74 ngx_string("HIT") |
75 }; | |
76 | |
77 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
78 static u_char ngx_http_file_cache_key[] = { LF, 'K', 'E', 'Y', ':', ' ' }; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
79 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
81 static ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
82 ngx_http_file_cache_init(ngx_shm_zone_t *shm_zone, void *data) |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
84 ngx_http_file_cache_t *ocache = data; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
86 size_t len; |
3017
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
87 ngx_uint_t n; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
88 ngx_http_file_cache_t *cache; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
89 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
90 cache = shm_zone->data; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
91 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
92 if (ocache) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
93 if (ngx_strcmp(cache->path->name.data, ocache->path->name.data) != 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
94 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
95 "cache \"%V\" uses the \"%V\" cache path " |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
96 "while previously it used the \"%V\" cache path", |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2694
diff
changeset
|
97 &shm_zone->shm.name, &cache->path->name, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
98 &ocache->path->name); |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
99 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 return NGX_ERROR; |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
101 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
102 |
3017
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
103 for (n = 0; n < 3; n++) { |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
104 if (cache->path->level[n] != ocache->path->level[n]) { |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
105 ngx_log_error(NGX_LOG_EMERG, shm_zone->shm.log, 0, |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
106 "cache \"%V\" had previously different levels", |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
107 &shm_zone->shm.name); |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
108 return NGX_ERROR; |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
109 } |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
110 } |
c466605d9426
test cache path levels while reconfiguration
Igor Sysoev <igor@sysoev.ru>
parents:
2952
diff
changeset
|
111 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
112 cache->sh = ocache->sh; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
113 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
114 cache->shpool = ocache->shpool; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
115 cache->bsize = ocache->bsize; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
116 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
117 cache->max_size /= cache->bsize; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
118 |
3018 | 119 if (!cache->sh->cold || cache->sh->loading) { |
120 cache->path->loader = NULL; | |
121 } | |
122 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
123 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
124 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
125 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
126 cache->shpool = (ngx_slab_pool_t *) shm_zone->shm.addr; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
127 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
128 if (shm_zone->shm.exists) { |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
129 cache->sh = cache->shpool->data; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
130 cache->bsize = ngx_fs_bsize(cache->path->name.data); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
131 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
132 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
133 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
134 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
135 cache->sh = ngx_slab_alloc(cache->shpool, sizeof(ngx_http_file_cache_sh_t)); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
136 if (cache->sh == NULL) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
137 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
138 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
139 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
140 cache->shpool->data = cache->sh; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
141 |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
142 ngx_rbtree_init(&cache->sh->rbtree, &cache->sh->sentinel, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
143 ngx_http_file_cache_rbtree_insert_value); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
144 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
145 ngx_queue_init(&cache->sh->queue); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
146 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
147 cache->sh->cold = 1; |
3018 | 148 cache->sh->loading = 0; |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
149 cache->sh->size = 0; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
150 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
151 cache->bsize = ngx_fs_bsize(cache->path->name.data); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
152 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
153 cache->max_size /= cache->bsize; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
154 |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2694
diff
changeset
|
155 len = sizeof(" in cache keys zone \"\"") + shm_zone->shm.name.len; |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
156 |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
157 cache->shpool->log_ctx = ngx_slab_alloc(cache->shpool, len); |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
158 if (cache->shpool->log_ctx == NULL) { |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
159 return NGX_ERROR; |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
160 } |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
161 |
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
162 ngx_sprintf(cache->shpool->log_ctx, " in cache keys zone \"%V\"%Z", |
2716
d5896f6608e8
move zone name from ngx_shm_zone_t to ngx_shm_t to use Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2694
diff
changeset
|
163 &shm_zone->shm.name); |
2611
2bce3f6416c6
improve ngx_slab_alloc() error logging
Igor Sysoev <igor@sysoev.ru>
parents:
2606
diff
changeset
|
164 |
5822
063f7e75f9ef
Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents:
5737
diff
changeset
|
165 cache->shpool->log_nomem = 0; |
063f7e75f9ef
Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents:
5737
diff
changeset
|
166 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
167 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
168 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
169 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
170 |
3697 | 171 ngx_int_t |
3698
d11227f0107f
rename ngx_http_file_cache_create() to ngx_http_file_cache_new()
Igor Sysoev <igor@sysoev.ru>
parents:
3697
diff
changeset
|
172 ngx_http_file_cache_new(ngx_http_request_t *r) |
3697 | 173 { |
174 ngx_http_cache_t *c; | |
175 | |
176 c = ngx_pcalloc(r->pool, sizeof(ngx_http_cache_t)); | |
177 if (c == NULL) { | |
178 return NGX_ERROR; | |
179 } | |
180 | |
181 if (ngx_array_init(&c->keys, r->pool, 4, sizeof(ngx_str_t)) != NGX_OK) { | |
182 return NGX_ERROR; | |
183 } | |
184 | |
185 r->cache = c; | |
186 c->file.log = r->connection->log; | |
3704
f220e5a5fb5e
initialize r->cache->file.fd with NGX_INVALID_FILE
Igor Sysoev <igor@sysoev.ru>
parents:
3699
diff
changeset
|
187 c->file.fd = NGX_INVALID_FILE; |
3697 | 188 |
189 return NGX_OK; | |
190 } | |
191 | |
192 | |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
193 ngx_int_t |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
194 ngx_http_file_cache_create(ngx_http_request_t *r) |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
195 { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
196 ngx_http_cache_t *c; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
197 ngx_pool_cleanup_t *cln; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
198 ngx_http_file_cache_t *cache; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
199 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
200 c = r->cache; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
201 cache = c->file_cache; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
202 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
203 cln = ngx_pool_cleanup_add(r->pool, 0); |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
204 if (cln == NULL) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
205 return NGX_ERROR; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
206 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
207 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
208 cln->handler = ngx_http_file_cache_cleanup; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
209 cln->data = c; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
210 |
3699
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
211 if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
212 return NGX_ERROR; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
213 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
214 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
215 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) { |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
216 return NGX_ERROR; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
217 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
218 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
219 return NGX_OK; |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
220 } |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
221 |
b0a0686a85bb
proxy_cache_pass, fastcgi_cache_bypass, uwsgi_cache_bypass, scgi_cache_bypass
Igor Sysoev <igor@sysoev.ru>
parents:
3698
diff
changeset
|
222 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
223 void |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
224 ngx_http_file_cache_create_key(ngx_http_request_t *r) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
225 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
226 size_t len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
227 ngx_str_t *key; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
228 ngx_uint_t i; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
229 ngx_md5_t md5; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
230 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
231 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
232 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
233 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
234 len = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
235 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
236 ngx_crc32_init(c->crc32); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
237 ngx_md5_init(&md5); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
238 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
239 key = c->keys.elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
240 for (i = 0; i < c->keys.nelts; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
241 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
242 "http cache key: \"%V\"", &key[i]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
243 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
244 len += key[i].len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
245 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
246 ngx_crc32_update(&c->crc32, key[i].data, key[i].len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
247 ngx_md5_update(&md5, key[i].data, key[i].len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
248 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
249 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
250 c->header_start = sizeof(ngx_http_file_cache_header_t) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
251 + sizeof(ngx_http_file_cache_key) + len + 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
252 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
253 ngx_crc32_final(c->crc32); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
254 ngx_md5_final(c->key, &md5); |
5880
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
255 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
256 ngx_memcpy(c->main, c->key, NGX_HTTP_CACHE_KEY_LEN); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
257 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
258 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
259 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
260 ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
261 ngx_http_file_cache_open(ngx_http_request_t *r) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
262 { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
263 ngx_int_t rc, rv; |
5984
3f568dd68af1
Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
264 ngx_uint_t test; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
265 ngx_http_cache_t *c; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
266 ngx_pool_cleanup_t *cln; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
267 ngx_open_file_info_t of; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
268 ngx_http_file_cache_t *cache; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
269 ngx_http_core_loc_conf_t *clcf; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
270 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
271 c = r->cache; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
272 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
273 if (c->waiting) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
274 return NGX_AGAIN; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
275 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
276 |
5879
c525c0454aa5
Cache: c->reading flag introduced.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5878
diff
changeset
|
277 if (c->reading) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
278 return ngx_http_file_cache_read(r, c); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
279 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
280 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
281 cache = c->file_cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
282 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
283 if (c->node == NULL) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
284 cln = ngx_pool_cleanup_add(r->pool, 0); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
285 if (cln == NULL) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
286 return NGX_ERROR; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
287 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
288 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
289 cln->handler = ngx_http_file_cache_cleanup; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
290 cln->data = c; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
291 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
292 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
293 rc = ngx_http_file_cache_exists(cache, c); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
294 |
2926
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2925
diff
changeset
|
295 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
80a314b63c56
delete useless r->cache->uses
Igor Sysoev <igor@sysoev.ru>
parents:
2925
diff
changeset
|
296 "http file cache exists: %i e:%d", rc, c->exists); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
297 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
298 if (rc == NGX_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
299 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
300 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
301 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
302 if (rc == NGX_AGAIN) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
303 return NGX_HTTP_CACHE_SCARCE; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
304 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
305 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
306 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
307 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
308 if (c->error) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
309 return c->error; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
310 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
311 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
312 c->temp_file = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
313 test = c->exists ? 1 : 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
314 rv = NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
315 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
316 } else { /* rc == NGX_DECLINED */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
317 |
5984
3f568dd68af1
Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
318 test = cache->sh->cold ? 1 : 0; |
3f568dd68af1
Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
319 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
320 if (c->min_uses > 1) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
321 |
5984
3f568dd68af1
Cache: reduced diffs to the plus version of nginx.
Ruslan Ermilov <ru@nginx.com>
parents:
5968
diff
changeset
|
322 if (!test) { |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
323 return NGX_HTTP_CACHE_SCARCE; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
324 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
325 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
326 rv = NGX_HTTP_CACHE_SCARCE; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
327 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
328 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
329 c->temp_file = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
330 rv = NGX_DECLINED; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
331 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
332 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
333 |
3696 | 334 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
335 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
336 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
337 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
338 if (!test) { |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
339 goto done; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
340 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
341 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
342 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
343 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
344 ngx_memzero(&of, sizeof(ngx_open_file_info_t)); |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
345 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
346 of.uniq = c->uniq; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
347 of.valid = clcf->open_file_cache_valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
348 of.min_uses = clcf->open_file_cache_min_uses; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
349 of.events = clcf->open_file_cache_events; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
350 of.directio = NGX_OPEN_FILE_DIRECTIO_OFF; |
3178 | 351 of.read_ahead = clcf->read_ahead; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
352 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
353 if (ngx_open_cached_file(clcf->open_file_cache, &c->file.name, &of, r->pool) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
354 != NGX_OK) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
355 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
356 switch (of.err) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
357 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
358 case 0: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
359 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
360 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
361 case NGX_ENOENT: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
362 case NGX_ENOTDIR: |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
363 goto done; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
364 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
365 default: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
366 ngx_log_error(NGX_LOG_CRIT, r->connection->log, of.err, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
367 ngx_open_file_n " \"%s\" failed", c->file.name.data); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
368 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
369 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
370 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
371 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
372 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
373 "http file cache fd: %d", of.fd); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
374 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
375 c->file.fd = of.fd; |
2603
f9bd7999eb08
fix segfault if ngx_read_file() will fail
Igor Sysoev <igor@sysoev.ru>
parents:
2600
diff
changeset
|
376 c->file.log = r->connection->log; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
377 c->uniq = of.uniq; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
378 c->length = of.size; |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
379 c->fs_size = (of.fs_size + cache->bsize - 1) / cache->bsize; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
380 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
381 c->buf = ngx_create_temp_buf(r->pool, c->body_start); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
382 if (c->buf == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
383 return NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
384 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
385 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
386 return ngx_http_file_cache_read(r, c); |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
387 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
388 done: |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
389 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
390 if (rv == NGX_DECLINED) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
391 return ngx_http_file_cache_lock(r, c); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
392 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
393 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
394 return rv; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
395 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
396 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
397 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
398 static ngx_int_t |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
399 ngx_http_file_cache_lock(ngx_http_request_t *r, ngx_http_cache_t *c) |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
400 { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
401 ngx_msec_t now, timer; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
402 ngx_http_file_cache_t *cache; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
403 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
404 if (!c->lock) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
405 return NGX_DECLINED; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
406 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
407 |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
408 now = ngx_current_msec; |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
409 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
410 cache = c->file_cache; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
411 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
412 ngx_shmtx_lock(&cache->shpool->mutex); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
413 |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
414 timer = c->node->lock_time - now; |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
415 |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
416 if (!c->node->updating || (ngx_msec_int_t) timer <= 0) { |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
417 c->node->updating = 1; |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
418 c->node->lock_time = now + c->lock_age; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
419 c->updating = 1; |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
420 c->lock_time = c->node->lock_time; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
421 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
422 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
423 ngx_shmtx_unlock(&cache->shpool->mutex); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
424 |
4387
e8181eeddaf8
Fixed build without debug.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4385
diff
changeset
|
425 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
426 "http file cache lock u:%d wt:%M", |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
427 c->updating, c->wait_time); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
428 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
429 if (c->updating) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
430 return NGX_DECLINED; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
431 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
432 |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
433 if (c->lock_timeout == 0) { |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
434 return NGX_HTTP_CACHE_SCARCE; |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
435 } |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
436 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
437 c->waiting = 1; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
438 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
439 if (c->wait_time == 0) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
440 c->wait_time = now + c->lock_timeout; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
441 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
442 c->wait_event.handler = ngx_http_file_cache_lock_wait_handler; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
443 c->wait_event.data = r; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
444 c->wait_event.log = r->connection->log; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
445 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
446 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
447 timer = c->wait_time - now; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
448 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
449 ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
450 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
451 r->main->blocked++; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
452 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
453 return NGX_AGAIN; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
454 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
455 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
456 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
457 static void |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
458 ngx_http_file_cache_lock_wait_handler(ngx_event_t *ev) |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
459 { |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
460 ngx_connection_t *c; |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
461 ngx_http_request_t *r; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
462 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
463 r = ev->data; |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
464 c = r->connection; |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
465 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
466 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
467 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
468 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
469 "http file cache wait: \"%V?%V\"", &r->uri, &r->args); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
470 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
471 ngx_http_file_cache_lock_wait(r, r->cache); |
5929
f436e9a60b8f
Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5928
diff
changeset
|
472 |
f436e9a60b8f
Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5928
diff
changeset
|
473 ngx_http_run_posted_requests(c); |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
474 } |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
475 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
476 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
477 static void |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
478 ngx_http_file_cache_lock_wait(ngx_http_request_t *r, ngx_http_cache_t *c) |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
479 { |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
480 ngx_uint_t wait; |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
481 ngx_msec_t now, timer; |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
482 ngx_http_file_cache_t *cache; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
483 |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
484 now = ngx_current_msec; |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
485 |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
486 timer = c->wait_time - now; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
487 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
488 if ((ngx_msec_int_t) timer <= 0) { |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
489 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
490 "cache lock timeout"); |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
491 c->lock_timeout = 0; |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
492 goto wakeup; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
493 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
494 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
495 cache = c->file_cache; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
496 wait = 0; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
497 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
498 ngx_shmtx_lock(&cache->shpool->mutex); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
499 |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
500 timer = c->node->lock_time - now; |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
501 |
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
502 if (c->node->updating && (ngx_msec_int_t) timer > 0) { |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
503 wait = 1; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
504 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
505 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
506 ngx_shmtx_unlock(&cache->shpool->mutex); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
507 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
508 if (wait) { |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
509 ngx_add_timer(&c->wait_event, (timer > 500) ? 500 : timer); |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
510 return; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
511 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
512 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
513 wakeup: |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
514 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
515 c->waiting = 0; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
516 r->main->blocked--; |
5929
f436e9a60b8f
Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5928
diff
changeset
|
517 r->write_event_handler(r); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
518 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
519 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
520 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
521 static ngx_int_t |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
522 ngx_http_file_cache_read(ngx_http_request_t *r, ngx_http_cache_t *c) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
523 { |
6243
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
524 u_char *p; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
525 time_t now; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
526 ssize_t n; |
6243
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
527 ngx_str_t *key; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
528 ngx_int_t rc; |
6243
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
529 ngx_uint_t i; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
530 ngx_http_file_cache_t *cache; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
531 ngx_http_file_cache_header_t *h; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
532 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
533 n = ngx_http_file_cache_aio_read(r, c); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
534 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
535 if (n < 0) { |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
536 return n; |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
537 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
538 |
3369
479468a7d982
fix handling cached HTTP/0.9 response
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
539 if ((size_t) n < c->header_start) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
540 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
477 | 541 "cache file \"%s\" is too small", c->file.name.data); |
3971
44f4fc874b2f
do not close connection if cache file is too small: replace it with valid one
Igor Sysoev <igor@sysoev.ru>
parents:
3970
diff
changeset
|
542 return NGX_DECLINED; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
543 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
544 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
545 h = (ngx_http_file_cache_header_t *) c->buf->pos; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
546 |
5736
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
547 if (h->version != NGX_HTTP_CACHE_VERSION) { |
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
548 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, |
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
549 "cache file \"%s\" version mismatch", c->file.name.data); |
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
550 return NGX_DECLINED; |
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
551 } |
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
552 |
6243
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
553 if (h->crc32 != c->crc32 || h->header_start != c->header_start) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
554 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
555 "cache file \"%s\" has md5 collision", c->file.name.data); |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
556 return NGX_DECLINED; |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
557 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
558 |
6243
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
559 p = c->buf->pos + sizeof(ngx_http_file_cache_header_t) |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
560 + sizeof(ngx_http_file_cache_key); |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
561 |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
562 key = c->keys.elts; |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
563 for (i = 0; i < c->keys.nelts; i++) { |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
564 if (ngx_memcmp(p, key[i].data, key[i].len) != 0) { |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
565 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
566 "cache file \"%s\" has md5 collision", |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
567 c->file.name.data); |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
568 return NGX_DECLINED; |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
569 } |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
570 |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
571 p += key[i].len; |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
572 } |
4821fc788c12
Cache: check the whole cache key in addition to hashes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6063
diff
changeset
|
573 |
5359
2fda9065d0f4
Win32: Borland C compatibility fixes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5341
diff
changeset
|
574 if ((size_t) h->body_start > c->body_start) { |
4339
6f97afc238de
Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4338
diff
changeset
|
575 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
6f97afc238de
Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4338
diff
changeset
|
576 "cache file \"%s\" has too long header", |
6f97afc238de
Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4338
diff
changeset
|
577 c->file.name.data); |
6f97afc238de
Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4338
diff
changeset
|
578 return NGX_DECLINED; |
6f97afc238de
Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4338
diff
changeset
|
579 } |
6f97afc238de
Cache: handling of cache files with long headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4338
diff
changeset
|
580 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
581 if (h->vary_len > NGX_HTTP_CACHE_VARY_LEN) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
582 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
583 "cache file \"%s\" has incorrect vary length", |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
584 c->file.name.data); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
585 return NGX_DECLINED; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
586 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
587 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
588 if (h->vary_len) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
589 ngx_http_file_cache_vary(r, h->vary, h->vary_len, c->variant); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
590 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
591 if (ngx_memcmp(c->variant, h->variant, NGX_HTTP_CACHE_KEY_LEN) != 0) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
592 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
593 "http file cache vary mismatch"); |
5880
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
594 return ngx_http_file_cache_reopen(r, c); |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
595 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
596 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
597 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
598 c->buf->last += n; |
477 | 599 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
600 c->valid_sec = h->valid_sec; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
601 c->last_modified = h->last_modified; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
602 c->date = h->date; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
603 c->valid_msec = h->valid_msec; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
604 c->body_start = h->body_start; |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
605 c->etag.len = h->etag_len; |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
606 c->etag.data = h->etag; |
477 | 607 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
608 r->cached = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
609 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
610 cache = c->file_cache; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
611 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
612 if (cache->sh->cold) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
613 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
614 ngx_shmtx_lock(&cache->shpool->mutex); |
477 | 615 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
616 if (!c->node->exists) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
617 c->node->uses = 1; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
618 c->node->body_start = c->body_start; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
619 c->node->exists = 1; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
620 c->node->uniq = c->uniq; |
4034
e2c075e774b6
Cache size accounting fix: actual cache size on disk was less than
Igor Sysoev <igor@sysoev.ru>
parents:
4018
diff
changeset
|
621 c->node->fs_size = c->fs_size; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
622 |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
623 cache->sh->size += c->fs_size; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
624 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
625 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
626 ngx_shmtx_unlock(&cache->shpool->mutex); |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
627 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
628 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
629 now = ngx_time(); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
630 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
631 if (c->valid_sec < now) { |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
632 |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
633 ngx_shmtx_lock(&cache->shpool->mutex); |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
634 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
635 if (c->node->updating) { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
636 rc = NGX_HTTP_CACHE_UPDATING; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
637 |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
638 } else { |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
639 c->node->updating = 1; |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
640 c->updating = 1; |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
641 c->lock_time = c->node->lock_time; |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
642 rc = NGX_HTTP_CACHE_STALE; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
643 } |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
644 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
645 ngx_shmtx_unlock(&cache->shpool->mutex); |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
646 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
647 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
648 "http file cache expired: %i %T %T", |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
649 rc, c->valid_sec, now); |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
650 |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
651 return rc; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
652 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
653 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
654 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
655 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
656 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
657 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
658 static ssize_t |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
659 ngx_http_file_cache_aio_read(ngx_http_request_t *r, ngx_http_cache_t *c) |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
660 { |
6063
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
661 #if (NGX_HAVE_FILE_AIO || NGX_THREADS) |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
662 ssize_t n; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
663 ngx_http_core_loc_conf_t *clcf; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
664 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
665 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
6063
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
666 #endif |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
667 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
668 #if (NGX_HAVE_FILE_AIO) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
669 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
670 if (clcf->aio == NGX_HTTP_AIO_ON && ngx_file_aio) { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
671 n = ngx_file_aio_read(&c->file, c->buf->pos, c->body_start, 0, r->pool); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
672 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
673 if (n != NGX_AGAIN) { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
674 c->reading = 0; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
675 return n; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
676 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
677 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
678 c->reading = 1; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
679 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
680 c->file.aio->data = r; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
681 c->file.aio->handler = ngx_http_cache_aio_event_handler; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
682 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
683 r->main->blocked++; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
684 r->aio = 1; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
685 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
686 return NGX_AGAIN; |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
687 } |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
688 |
6063
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
689 #endif |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
690 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
691 #if (NGX_THREADS) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
692 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
693 if (clcf->aio == NGX_HTTP_AIO_THREADS) { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
694 c->file.thread_handler = ngx_http_cache_thread_handler; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
695 c->file.thread_ctx = r; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
696 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
697 n = ngx_thread_read(&c->thread_task, &c->file, c->buf->pos, |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
698 c->body_start, 0, r->pool); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
699 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
700 c->reading = (n == NGX_AGAIN); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
701 |
3294
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
702 return n; |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
703 } |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
704 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
705 #endif |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
706 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
707 return ngx_read_file(&c->file, c->buf->pos, c->body_start, 0); |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
708 } |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
709 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
710 |
04cfc09b8b8d
export aio presence knowledge to prevent using "aio sendfile",
Igor Sysoev <igor@sysoev.ru>
parents:
3195
diff
changeset
|
711 #if (NGX_HAVE_FILE_AIO) |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
712 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
713 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
714 ngx_http_cache_aio_event_handler(ngx_event_t *ev) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
715 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
716 ngx_event_aio_t *aio; |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
717 ngx_connection_t *c; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
718 ngx_http_request_t *r; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
719 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
720 aio = ev->data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
721 r = aio->data; |
5928
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
722 c = r->connection; |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
723 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
724 ngx_http_set_log_request(c->log, r); |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
725 |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
726 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
8dfee01ff0bd
Upstream: improved subrequest logging.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5905
diff
changeset
|
727 "http file cache aio: \"%V?%V\"", &r->uri, &r->args); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
728 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
729 r->main->blocked--; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
730 r->aio = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
731 |
5929
f436e9a60b8f
Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5928
diff
changeset
|
732 r->write_event_handler(r); |
f436e9a60b8f
Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5928
diff
changeset
|
733 |
f436e9a60b8f
Cache: proper wakeup of subrequests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5928
diff
changeset
|
734 ngx_http_run_posted_requests(c); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
735 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
736 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
737 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
738 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3024
diff
changeset
|
739 |
6063
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
740 #if (NGX_THREADS) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
741 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
742 static ngx_int_t |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
743 ngx_http_cache_thread_handler(ngx_thread_task_t *task, ngx_file_t *file) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
744 { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
745 ngx_str_t name; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
746 ngx_thread_pool_t *tp; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
747 ngx_http_request_t *r; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
748 ngx_http_core_loc_conf_t *clcf; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
749 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
750 r = file->thread_ctx; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
751 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
752 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
753 tp = clcf->thread_pool; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
754 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
755 if (tp == NULL) { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
756 if (ngx_http_complex_value(r, clcf->thread_pool_value, &name) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
757 != NGX_OK) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
758 { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
759 return NGX_ERROR; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
760 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
761 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
762 tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
763 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
764 if (tp == NULL) { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
765 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
766 "thread pool \"%V\" not found", &name); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
767 return NGX_ERROR; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
768 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
769 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
770 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
771 task->event.data = r; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
772 task->event.handler = ngx_http_cache_thread_event_handler; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
773 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
774 if (ngx_thread_task_post(tp, task) != NGX_OK) { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
775 return NGX_ERROR; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
776 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
777 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
778 r->main->blocked++; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
779 r->aio = 1; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
780 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
781 return NGX_OK; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
782 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
783 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
784 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
785 static void |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
786 ngx_http_cache_thread_event_handler(ngx_event_t *ev) |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
787 { |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
788 ngx_connection_t *c; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
789 ngx_http_request_t *r; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
790 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
791 r = ev->data; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
792 c = r->connection; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
793 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
794 ngx_http_set_log_request(c->log, r); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
795 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
796 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
797 "http file cache thread: \"%V?%V\"", &r->uri, &r->args); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
798 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
799 r->main->blocked--; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
800 r->aio = 0; |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
801 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
802 r->write_event_handler(r); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
803 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
804 ngx_http_run_posted_requests(c); |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
805 } |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
806 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
807 #endif |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
808 |
d698c300b9ff
Cache: added support for reading of the header in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
809 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
810 static ngx_int_t |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
811 ngx_http_file_cache_exists(ngx_http_file_cache_t *cache, ngx_http_cache_t *c) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
812 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
813 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
814 ngx_http_file_cache_node_t *fcn; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
815 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
816 ngx_shmtx_lock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
817 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
818 fcn = c->node; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
819 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
820 if (fcn == NULL) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
821 fcn = ngx_http_file_cache_lookup(cache, c->key); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
822 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
823 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
824 if (fcn) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
825 ngx_queue_remove(&fcn->queue); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
826 |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
827 if (c->node == NULL) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
828 fcn->uses++; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
829 fcn->count++; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
830 } |
3724
e9f0a2497d3c
count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents:
3723
diff
changeset
|
831 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
832 if (fcn->error) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
833 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
834 if (fcn->valid_sec < ngx_time()) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
835 goto renew; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
836 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
837 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
838 rc = NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
839 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
840 goto done; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
841 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
842 |
3966
9c425f22ea36
fuse two if's in one condition
Igor Sysoev <igor@sysoev.ru>
parents:
3965
diff
changeset
|
843 if (fcn->exists || fcn->uses >= c->min_uses) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
844 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
845 c->exists = fcn->exists; |
3969 | 846 if (fcn->body_start) { |
3967
83e41f6f6d96
The cache loader performs two tasks: inserting cache objects in inactivity
Igor Sysoev <igor@sysoev.ru>
parents:
3966
diff
changeset
|
847 c->body_start = fcn->body_start; |
83e41f6f6d96
The cache loader performs two tasks: inserting cache objects in inactivity
Igor Sysoev <igor@sysoev.ru>
parents:
3966
diff
changeset
|
848 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
849 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
850 rc = NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
851 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
852 goto done; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
853 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
854 |
3966
9c425f22ea36
fuse two if's in one condition
Igor Sysoev <igor@sysoev.ru>
parents:
3965
diff
changeset
|
855 rc = NGX_AGAIN; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
856 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
857 goto done; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
858 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
859 |
5726
25ade23cf281
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents:
5679
diff
changeset
|
860 fcn = ngx_slab_calloc_locked(cache->shpool, |
25ade23cf281
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents:
5679
diff
changeset
|
861 sizeof(ngx_http_file_cache_node_t)); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
862 if (fcn == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
863 ngx_shmtx_unlock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
864 |
2693 | 865 (void) ngx_http_file_cache_forced_expire(cache); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
866 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
867 ngx_shmtx_lock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
868 |
5726
25ade23cf281
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents:
5679
diff
changeset
|
869 fcn = ngx_slab_calloc_locked(cache->shpool, |
25ade23cf281
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents:
5679
diff
changeset
|
870 sizeof(ngx_http_file_cache_node_t)); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
871 if (fcn == NULL) { |
5822
063f7e75f9ef
Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents:
5737
diff
changeset
|
872 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, |
063f7e75f9ef
Upstream: suppressed the file cache slab allocator error messages.
Roman Arutyunyan <arut@nginx.com>
parents:
5737
diff
changeset
|
873 "could not allocate node%s", cache->shpool->log_ctx); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
874 rc = NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
875 goto failed; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
876 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
877 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
878 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
879 ngx_memcpy((u_char *) &fcn->node.key, c->key, sizeof(ngx_rbtree_key_t)); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
880 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
881 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)], |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
882 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
883 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
884 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
885 |
3724
e9f0a2497d3c
count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents:
3723
diff
changeset
|
886 fcn->uses = 1; |
e9f0a2497d3c
count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents:
3723
diff
changeset
|
887 fcn->count = 1; |
e9f0a2497d3c
count cache key node usage for cached error statuses
Igor Sysoev <igor@sysoev.ru>
parents:
3723
diff
changeset
|
888 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
889 renew: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
890 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
891 rc = NGX_DECLINED; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
892 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
893 fcn->valid_msec = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
894 fcn->error = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
895 fcn->exists = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
896 fcn->valid_sec = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
897 fcn->uniq = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
898 fcn->body_start = 0; |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
899 fcn->fs_size = 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
900 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
901 done: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
902 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
903 fcn->expire = ngx_time() + cache->inactive; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
904 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
905 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
906 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
907 c->uniq = fcn->uniq; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
908 c->error = fcn->error; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
909 c->node = fcn; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
910 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
911 failed: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
912 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
913 ngx_shmtx_unlock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
914 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
915 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
916 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
917 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
918 |
3696 | 919 static ngx_int_t |
920 ngx_http_file_cache_name(ngx_http_request_t *r, ngx_path_t *path) | |
921 { | |
922 u_char *p; | |
923 ngx_http_cache_t *c; | |
924 | |
925 c = r->cache; | |
926 | |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
927 if (c->file.name.len) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
928 return NGX_OK; |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
929 } |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
930 |
3696 | 931 c->file.name.len = path->name.len + 1 + path->len |
932 + 2 * NGX_HTTP_CACHE_KEY_LEN; | |
933 | |
934 c->file.name.data = ngx_pnalloc(r->pool, c->file.name.len + 1); | |
935 if (c->file.name.data == NULL) { | |
936 return NGX_ERROR; | |
937 } | |
938 | |
939 ngx_memcpy(c->file.name.data, path->name.data, path->name.len); | |
940 | |
941 p = c->file.name.data + path->name.len + 1 + path->len; | |
942 p = ngx_hex_dump(p, c->key, NGX_HTTP_CACHE_KEY_LEN); | |
943 *p = '\0'; | |
944 | |
945 ngx_create_hashed_filename(path, c->file.name.data, c->file.name.len); | |
946 | |
947 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
948 "cache file: \"%s\"", c->file.name.data); | |
949 | |
950 return NGX_OK; | |
951 } | |
952 | |
953 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
954 static ngx_http_file_cache_node_t * |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
955 ngx_http_file_cache_lookup(ngx_http_file_cache_t *cache, u_char *key) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
956 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
957 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
958 ngx_rbtree_key_t node_key; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
959 ngx_rbtree_node_t *node, *sentinel; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
960 ngx_http_file_cache_node_t *fcn; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
961 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
962 ngx_memcpy((u_char *) &node_key, key, sizeof(ngx_rbtree_key_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
963 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
964 node = cache->sh->rbtree.root; |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
965 sentinel = cache->sh->rbtree.sentinel; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
966 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
967 while (node != sentinel) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
968 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
969 if (node_key < node->key) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
970 node = node->left; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
971 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
972 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
973 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
974 if (node_key > node->key) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
975 node = node->right; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
976 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
977 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
978 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
979 /* node_key == node->key */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
980 |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
981 fcn = (ngx_http_file_cache_node_t *) node; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
982 |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
983 rc = ngx_memcmp(&key[sizeof(ngx_rbtree_key_t)], fcn->key, |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
984 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
985 |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
986 if (rc == 0) { |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
987 return fcn; |
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
988 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
989 |
4497
95ab6658654a
Fix of rbtree lookup on hash collisions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4474
diff
changeset
|
990 node = (rc < 0) ? node->left : node->right; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
991 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
992 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
993 /* not found */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
994 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
995 return NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
996 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
997 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
998 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
999 static void |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1000 ngx_http_file_cache_rbtree_insert_value(ngx_rbtree_node_t *temp, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1001 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1002 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1003 ngx_rbtree_node_t **p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1004 ngx_http_file_cache_node_t *cn, *cnt; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1005 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1006 for ( ;; ) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1007 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1008 if (node->key < temp->key) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1009 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1010 p = &temp->left; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1011 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1012 } else if (node->key > temp->key) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1013 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1014 p = &temp->right; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1015 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1016 } else { /* node->key == temp->key */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1017 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1018 cn = (ngx_http_file_cache_node_t *) node; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1019 cnt = (ngx_http_file_cache_node_t *) temp; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1020 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1021 p = (ngx_memcmp(cn->key, cnt->key, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1022 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1023 < 0) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1024 ? &temp->left : &temp->right; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1025 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1026 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1027 if (*p == sentinel) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1028 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1029 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1030 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1031 temp = *p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1032 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1033 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1034 *p = node; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1035 node->parent = temp; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1036 node->left = sentinel; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1037 node->right = sentinel; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1038 ngx_rbt_red(node); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1039 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1040 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1041 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1042 static void |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1043 ngx_http_file_cache_vary(ngx_http_request_t *r, u_char *vary, size_t len, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1044 u_char *hash) |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1045 { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1046 u_char *p, *last; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1047 ngx_str_t name; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1048 ngx_md5_t md5; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1049 u_char buf[NGX_HTTP_CACHE_VARY_LEN]; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1050 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1051 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1052 "http file cache vary: \"%*s\"", len, vary); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1053 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1054 ngx_md5_init(&md5); |
5880
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1055 ngx_md5_update(&md5, r->cache->main, NGX_HTTP_CACHE_KEY_LEN); |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1056 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1057 ngx_strlow(buf, vary, len); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1058 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1059 p = buf; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1060 last = buf + len; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1061 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1062 while (p < last) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1063 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1064 while (p < last && (*p == ' ' || *p == ',')) { p++; } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1065 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1066 name.data = p; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1067 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1068 while (p < last && *p != ',' && *p != ' ') { p++; } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1069 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1070 name.len = p - name.data; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1071 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1072 if (name.len == 0) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1073 break; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1074 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1075 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1076 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1077 "http file cache vary: %V", &name); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1078 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1079 ngx_md5_update(&md5, name.data, name.len); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1080 ngx_md5_update(&md5, (u_char *) ":", sizeof(":") - 1); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1081 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1082 ngx_http_file_cache_vary_header(r, &md5, &name); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1083 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1084 ngx_md5_update(&md5, (u_char *) CRLF, sizeof(CRLF) - 1); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1085 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1086 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1087 ngx_md5_final(hash, &md5); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1088 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1089 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1090 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1091 static void |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1092 ngx_http_file_cache_vary_header(ngx_http_request_t *r, ngx_md5_t *md5, |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1093 ngx_str_t *name) |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1094 { |
5881
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1095 size_t len; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1096 u_char *p, *start, *last; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1097 ngx_uint_t i, multiple, normalize; |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1098 ngx_list_part_t *part; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1099 ngx_table_elt_t *header; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1100 |
5881
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1101 multiple = 0; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1102 normalize = 0; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1103 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1104 if (name->len == sizeof("Accept-Charset") - 1 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1105 && ngx_strncasecmp(name->data, (u_char *) "Accept-Charset", |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1106 sizeof("Accept-Charset") - 1) == 0) |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1107 { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1108 normalize = 1; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1109 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1110 } else if (name->len == sizeof("Accept-Encoding") - 1 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1111 && ngx_strncasecmp(name->data, (u_char *) "Accept-Encoding", |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1112 sizeof("Accept-Encoding") - 1) == 0) |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1113 { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1114 normalize = 1; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1115 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1116 } else if (name->len == sizeof("Accept-Language") - 1 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1117 && ngx_strncasecmp(name->data, (u_char *) "Accept-Language", |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1118 sizeof("Accept-Language") - 1) == 0) |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1119 { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1120 normalize = 1; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1121 } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1122 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1123 part = &r->headers_in.headers.part; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1124 header = part->elts; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1125 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1126 for (i = 0; /* void */ ; i++) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1127 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1128 if (i >= part->nelts) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1129 if (part->next == NULL) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1130 break; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1131 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1132 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1133 part = part->next; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1134 header = part->elts; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1135 i = 0; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1136 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1137 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1138 if (header[i].hash == 0) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1139 continue; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1140 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1141 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1142 if (header[i].key.len != name->len) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1143 continue; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1144 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1145 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1146 if (ngx_strncasecmp(header[i].key.data, name->data, name->len) != 0) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1147 continue; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1148 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1149 |
5881
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1150 if (!normalize) { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1151 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1152 if (multiple) { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1153 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1); |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1154 } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1155 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1156 ngx_md5_update(md5, header[i].value.data, header[i].value.len); |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1157 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1158 multiple = 1; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1159 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1160 continue; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1161 } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1162 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1163 /* normalize spaces */ |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1164 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1165 p = header[i].value.data; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1166 last = p + header[i].value.len; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1167 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1168 while (p < last) { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1169 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1170 while (p < last && (*p == ' ' || *p == ',')) { p++; } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1171 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1172 start = p; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1173 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1174 while (p < last && *p != ',' && *p != ' ') { p++; } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1175 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1176 len = p - start; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1177 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1178 if (len == 0) { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1179 break; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1180 } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1181 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1182 if (multiple) { |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1183 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1); |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1184 } |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1185 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1186 ngx_md5_update(md5, start, len); |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1187 |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1188 multiple = 1; |
ee9230cd4bda
Cache: normalization of some Vary headers.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5880
diff
changeset
|
1189 } |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1190 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1191 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1192 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1193 |
5880
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1194 static ngx_int_t |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1195 ngx_http_file_cache_reopen(ngx_http_request_t *r, ngx_http_cache_t *c) |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1196 { |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1197 ngx_http_file_cache_t *cache; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1198 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1199 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1200 "http file cache reopen"); |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1201 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1202 if (c->secondary) { |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1203 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1204 "cache file \"%s\" has incorrect vary hash", |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1205 c->file.name.data); |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1206 return NGX_DECLINED; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1207 } |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1208 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1209 cache = c->file_cache; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1210 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1211 ngx_shmtx_lock(&cache->shpool->mutex); |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1212 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1213 c->node->count--; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1214 c->node = NULL; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1215 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1216 ngx_shmtx_unlock(&cache->shpool->mutex); |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1217 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1218 c->secondary = 1; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1219 c->file.name.len = 0; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1220 c->body_start = c->buf->end - c->buf->start; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1221 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1222 ngx_memcpy(c->key, c->variant, NGX_HTTP_CACHE_KEY_LEN); |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1223 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1224 return ngx_http_file_cache_open(r); |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1225 } |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1226 |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1227 |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1228 ngx_int_t |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1229 ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1230 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1231 ngx_http_file_cache_header_t *h = (ngx_http_file_cache_header_t *) buf; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1232 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1233 u_char *p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1234 ngx_str_t *key; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1235 ngx_uint_t i; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1236 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1237 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1238 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1239 "http file cache set header"); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1240 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1241 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1242 |
5245
711fa02afae8
Valgrind: supressed complaints about uninitialized bytes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5077
diff
changeset
|
1243 ngx_memzero(h, sizeof(ngx_http_file_cache_header_t)); |
711fa02afae8
Valgrind: supressed complaints about uninitialized bytes.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5077
diff
changeset
|
1244 |
5736
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
1245 h->version = NGX_HTTP_CACHE_VERSION; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1246 h->valid_sec = c->valid_sec; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1247 h->last_modified = c->last_modified; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1248 h->date = c->date; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1249 h->crc32 = c->crc32; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1250 h->valid_msec = (u_short) c->valid_msec; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1251 h->header_start = (u_short) c->header_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1252 h->body_start = (u_short) c->body_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1253 |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1254 if (c->etag.len <= NGX_HTTP_CACHE_ETAG_LEN) { |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1255 h->etag_len = (u_char) c->etag.len; |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1256 ngx_memcpy(h->etag, c->etag.data, c->etag.len); |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1257 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1258 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1259 if (c->vary.len) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1260 if (c->vary.len > NGX_HTTP_CACHE_VARY_LEN) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1261 /* should not happen */ |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1262 c->vary.len = NGX_HTTP_CACHE_VARY_LEN; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1263 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1264 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1265 h->vary_len = (u_char) c->vary.len; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1266 ngx_memcpy(h->vary, c->vary.data, c->vary.len); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1267 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1268 ngx_http_file_cache_vary(r, c->vary.data, c->vary.len, c->variant); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1269 ngx_memcpy(h->variant, c->variant, NGX_HTTP_CACHE_KEY_LEN); |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1270 } |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1271 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1272 if (ngx_http_file_cache_update_variant(r, c) != NGX_OK) { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1273 return NGX_ERROR; |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1274 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1275 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1276 p = buf + sizeof(ngx_http_file_cache_header_t); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1277 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1278 p = ngx_cpymem(p, ngx_http_file_cache_key, sizeof(ngx_http_file_cache_key)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1279 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1280 key = c->keys.elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1281 for (i = 0; i < c->keys.nelts; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1282 p = ngx_copy(p, key[i].data, key[i].len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1283 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1284 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1285 *p = LF; |
5959
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1286 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1287 return NGX_OK; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1288 } |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1289 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1290 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1291 static ngx_int_t |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1292 ngx_http_file_cache_update_variant(ngx_http_request_t *r, ngx_http_cache_t *c) |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1293 { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1294 ngx_http_file_cache_t *cache; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1295 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1296 if (!c->secondary) { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1297 return NGX_OK; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1298 } |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1299 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1300 if (c->vary.len |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1301 && ngx_memcmp(c->variant, c->key, NGX_HTTP_CACHE_KEY_LEN) == 0) |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1302 { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1303 return NGX_OK; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1304 } |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1305 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1306 /* |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1307 * if the variant hash doesn't match one we used as a secondary |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1308 * cache key, switch back to the original key |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1309 */ |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1310 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1311 cache = c->file_cache; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1312 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1313 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1314 "http file cache main key"); |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1315 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1316 ngx_shmtx_lock(&cache->shpool->mutex); |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1317 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1318 c->node->count--; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1319 c->node->updating = 0; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1320 c->node = NULL; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1321 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1322 ngx_shmtx_unlock(&cache->shpool->mutex); |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1323 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1324 c->file.name.len = 0; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1325 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1326 ngx_memcpy(c->key, c->main, NGX_HTTP_CACHE_KEY_LEN); |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1327 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1328 if (ngx_http_file_cache_exists(cache, c) == NGX_ERROR) { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1329 return NGX_ERROR; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1330 } |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1331 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1332 if (ngx_http_file_cache_name(r, cache->path) != NGX_OK) { |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1333 return NGX_ERROR; |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1334 } |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1335 |
f7584d7c0ccb
Cache: update variant while setting header.
Valentin Bartenev <vbart@nginx.com>
parents:
5951
diff
changeset
|
1336 return NGX_OK; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1337 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1338 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1339 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1340 void |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1341 ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1342 { |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
1343 off_t fs_size; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1344 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1345 ngx_file_uniq_t uniq; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1346 ngx_file_info_t fi; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1347 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1348 ngx_ext_rename_file_t ext; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1349 ngx_http_file_cache_t *cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1350 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1351 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1352 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1353 if (c->updated) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1354 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1355 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1356 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1357 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1358 "http file cache update"); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1359 |
5880
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1360 cache = c->file_cache; |
78c49e243848
Cache: multiple variants of a resource now can be stored.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5879
diff
changeset
|
1361 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1362 c->updated = 1; |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1363 c->updating = 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1364 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1365 uniq = 0; |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
1366 fs_size = 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1367 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1368 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1369 "http file cache rename: \"%s\" to \"%s\"", |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1370 tf->file.name.data, c->file.name.data); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1371 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1372 ext.access = NGX_FILE_OWNER_ACCESS; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1373 ext.path_access = NGX_FILE_OWNER_ACCESS; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1374 ext.time = -1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1375 ext.create_path = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1376 ext.delete_file = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1377 ext.log = r->connection->log; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1378 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1379 rc = ngx_ext_rename_file(&tf->file.name, &c->file.name, &ext); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1380 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1381 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1382 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1383 if (ngx_fd_info(tf->file.fd, &fi) == NGX_FILE_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1384 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1385 ngx_fd_info_n " \"%s\" failed", tf->file.name.data); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1386 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1387 rc = NGX_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1388 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1389 } else { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1390 uniq = ngx_file_uniq(&fi); |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
1391 fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1392 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1393 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1394 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1395 ngx_shmtx_lock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1396 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1397 c->node->count--; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1398 c->node->uniq = uniq; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1399 c->node->body_start = c->body_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1400 |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
1401 cache->sh->size += fs_size - c->node->fs_size; |
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
1402 c->node->fs_size = fs_size; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1403 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1404 if (rc == NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1405 c->node->exists = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1406 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1407 |
2927
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
1408 c->node->updating = 0; |
55ceaef03d34
proxy_cache_use_stale/fastcgi_cache_use_stale updating
Igor Sysoev <igor@sysoev.ru>
parents:
2926
diff
changeset
|
1409 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1410 ngx_shmtx_unlock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1411 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1412 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1413 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1414 void |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1415 ngx_http_file_cache_update_header(ngx_http_request_t *r) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1416 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1417 ssize_t n; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1418 ngx_err_t err; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1419 ngx_file_t file; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1420 ngx_file_info_t fi; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1421 ngx_http_cache_t *c; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1422 ngx_http_file_cache_header_t h; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1423 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1424 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1425 "http file cache update header"); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1426 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1427 c = r->cache; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1428 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1429 ngx_memzero(&file, sizeof(ngx_file_t)); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1430 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1431 file.name = c->file.name; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1432 file.log = r->connection->log; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1433 file.fd = ngx_open_file(file.name.data, NGX_FILE_RDWR, NGX_FILE_OPEN, 0); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1434 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1435 if (file.fd == NGX_INVALID_FILE) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1436 err = ngx_errno; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1437 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1438 /* cache file may have been deleted */ |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1439 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1440 if (err == NGX_ENOENT) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1441 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1442 "http file cache \"%s\" not found", |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1443 file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1444 return; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1445 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1446 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1447 ngx_log_error(NGX_LOG_CRIT, r->connection->log, err, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1448 ngx_open_file_n " \"%s\" failed", file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1449 return; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1450 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1451 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1452 /* |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1453 * make sure cache file wasn't replaced; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1454 * if it was, do nothing |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1455 */ |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1456 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1457 if (ngx_fd_info(file.fd, &fi) == NGX_FILE_ERROR) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1458 ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1459 ngx_fd_info_n " \"%s\" failed", file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1460 goto done; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1461 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1462 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1463 if (c->uniq != ngx_file_uniq(&fi) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1464 || c->length != ngx_file_size(&fi)) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1465 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1466 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1467 "http file cache \"%s\" changed", |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1468 file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1469 goto done; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1470 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1471 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1472 n = ngx_read_file(&file, (u_char *) &h, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1473 sizeof(ngx_http_file_cache_header_t), 0); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1474 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1475 if (n == NGX_ERROR) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1476 goto done; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1477 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1478 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1479 if ((size_t) n != sizeof(ngx_http_file_cache_header_t)) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1480 ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1481 ngx_read_file_n " read only %z of %z from \"%s\"", |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1482 n, sizeof(ngx_http_file_cache_header_t), file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1483 goto done; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1484 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1485 |
5736
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
1486 if (h.version != NGX_HTTP_CACHE_VERSION |
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
1487 || h.last_modified != c->last_modified |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1488 || h.crc32 != c->crc32 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1489 || h.header_start != c->header_start |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1490 || h.body_start != c->body_start) |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1491 { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1492 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1493 "http file cache \"%s\" content changed", |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1494 file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1495 goto done; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1496 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1497 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1498 /* |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1499 * update cache file header with new data, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1500 * notably h.valid_sec and h.date |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1501 */ |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1502 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1503 ngx_memzero(&h, sizeof(ngx_http_file_cache_header_t)); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1504 |
5736
2fe1967f8854
Cache: version in cache files.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5726
diff
changeset
|
1505 h.version = NGX_HTTP_CACHE_VERSION; |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1506 h.valid_sec = c->valid_sec; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1507 h.last_modified = c->last_modified; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1508 h.date = c->date; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1509 h.crc32 = c->crc32; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1510 h.valid_msec = (u_short) c->valid_msec; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1511 h.header_start = (u_short) c->header_start; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1512 h.body_start = (u_short) c->body_start; |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1513 |
5737
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1514 if (c->etag.len <= NGX_HTTP_CACHE_ETAG_LEN) { |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1515 h.etag_len = (u_char) c->etag.len; |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1516 ngx_memcpy(h.etag, c->etag.data, c->etag.len); |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1517 } |
44b9ab7752e3
Cache: ETag now saved into cache header.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5736
diff
changeset
|
1518 |
5878
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1519 if (c->vary.len) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1520 if (c->vary.len > NGX_HTTP_CACHE_VARY_LEN) { |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1521 /* should not happen */ |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1522 c->vary.len = NGX_HTTP_CACHE_VARY_LEN; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1523 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1524 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1525 h.vary_len = (u_char) c->vary.len; |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1526 ngx_memcpy(h.vary, c->vary.data, c->vary.len); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1527 |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1528 ngx_http_file_cache_vary(r, c->vary.data, c->vary.len, c->variant); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1529 ngx_memcpy(h.variant, c->variant, NGX_HTTP_CACHE_KEY_LEN); |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1530 } |
2c89956b6a76
Cache: hash of Vary headers now stored in cache.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5822
diff
changeset
|
1531 |
5441
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1532 (void) ngx_write_file(&file, (u_char *) &h, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1533 sizeof(ngx_http_file_cache_header_t), 0); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1534 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1535 done: |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1536 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1537 if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1538 ngx_log_error(NGX_LOG_ALERT, r->connection->log, ngx_errno, |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1539 ngx_close_file_n " \"%s\" failed", file.name.data); |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1540 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1541 } |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1542 |
43ccaf8e8728
Upstream: cache revalidation with conditional requests.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5359
diff
changeset
|
1543 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1544 ngx_int_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1545 ngx_http_cache_send(ngx_http_request_t *r) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1546 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1547 ngx_int_t rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1548 ngx_buf_t *b; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1549 ngx_chain_t out; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1550 ngx_http_cache_t *c; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1551 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1552 c = r->cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1553 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1554 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
3965 | 1555 "http file cache send: %s", c->file.name.data); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1556 |
4150
b9ee14871bf1
Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4034
diff
changeset
|
1557 if (r != r->main && c->length - c->body_start == 0) { |
b9ee14871bf1
Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4034
diff
changeset
|
1558 return ngx_http_send_header(r); |
b9ee14871bf1
Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4034
diff
changeset
|
1559 } |
b9ee14871bf1
Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4034
diff
changeset
|
1560 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1561 /* we need to allocate all before the header would be sent */ |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1562 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1563 b = ngx_pcalloc(r->pool, sizeof(ngx_buf_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1564 if (b == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1565 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1566 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1567 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1568 b->file = ngx_pcalloc(r->pool, sizeof(ngx_file_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1569 if (b->file == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1570 return NGX_HTTP_INTERNAL_SERVER_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1571 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1572 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1573 rc = ngx_http_send_header(r); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1574 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1575 if (rc == NGX_ERROR || rc > NGX_OK || r->header_only) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1576 return rc; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1577 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1578 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1579 b->file_pos = c->body_start; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1580 b->file_last = c->length; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1581 |
4150
b9ee14871bf1
Cache: fix for sending of empty responses.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4034
diff
changeset
|
1582 b->in_file = (c->length - c->body_start) ? 1: 0; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1583 b->last_buf = (r == r->main) ? 1: 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1584 b->last_in_chain = 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1585 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1586 b->file->fd = c->file.fd; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1587 b->file->name = c->file.name; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1588 b->file->log = r->connection->log; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1589 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1590 out.buf = b; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1591 out.next = NULL; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1592 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1593 return ngx_http_output_filter(r, &out); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1594 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1595 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1596 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1597 void |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1598 ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1599 { |
3694
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1600 ngx_http_file_cache_t *cache; |
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1601 ngx_http_file_cache_node_t *fcn; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1602 |
3917
2a70484a6580
fix a broken cached response if bypass/no_cache directive values are different,
Igor Sysoev <igor@sysoev.ru>
parents:
3899
diff
changeset
|
1603 if (c->updated || c->node == NULL) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1604 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1605 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1606 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1607 cache = c->file_cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1608 |
3713
f0b62d1ac7af
move debug logging inside ngx_http_file_cache_free()
Igor Sysoev <igor@sysoev.ru>
parents:
3711
diff
changeset
|
1609 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
f0b62d1ac7af
move debug logging inside ngx_http_file_cache_free()
Igor Sysoev <igor@sysoev.ru>
parents:
3711
diff
changeset
|
1610 "http file cache free, fd: %d", c->file.fd); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1611 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1612 ngx_shmtx_lock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1613 |
3694
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1614 fcn = c->node; |
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1615 fcn->count--; |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1616 |
5905
2f7e557eab5b
Cache: proxy_cache_lock_age and friends.
Roman Arutyunyan <arut@nginx.com>
parents:
5898
diff
changeset
|
1617 if (c->updating && fcn->lock_time == c->lock_time) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1618 fcn->updating = 0; |
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1619 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1620 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1621 if (c->error) { |
3694
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1622 fcn->error = c->error; |
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1623 |
3743
c469ffeab569
error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents:
3732
diff
changeset
|
1624 if (c->valid_sec) { |
c469ffeab569
error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents:
3732
diff
changeset
|
1625 fcn->valid_sec = c->valid_sec; |
c469ffeab569
error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents:
3732
diff
changeset
|
1626 fcn->valid_msec = c->valid_msec; |
c469ffeab569
error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents:
3732
diff
changeset
|
1627 } |
c469ffeab569
error status codes could be cached for next request only,
Igor Sysoev <igor@sysoev.ru>
parents:
3732
diff
changeset
|
1628 |
3723
14ad3210fc73
do not free unused cache node if cache min_uses > 1,
Igor Sysoev <igor@sysoev.ru>
parents:
3713
diff
changeset
|
1629 } else if (!fcn->exists && fcn->count == 0 && c->min_uses == 1) { |
3694
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1630 ngx_queue_remove(&fcn->queue); |
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1631 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); |
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1632 ngx_slab_free_locked(cache->shpool, fcn); |
dfb17155eca9
delete empty cache zone node if we could not get response to cache
Igor Sysoev <igor@sysoev.ru>
parents:
3526
diff
changeset
|
1633 c->node = NULL; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1634 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1635 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1636 ngx_shmtx_unlock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1637 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1638 c->updated = 1; |
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1639 c->updating = 0; |
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1640 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1641 if (c->temp_file) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1642 if (tf && tf->file.fd != NGX_INVALID_FILE) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1643 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1644 "http file cache incomplete: \"%s\"", |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1645 tf->file.name.data); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1646 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1647 if (ngx_delete_file(tf->file.name.data) == NGX_FILE_ERROR) { |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1648 ngx_log_error(NGX_LOG_CRIT, c->file.log, ngx_errno, |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1649 ngx_delete_file_n " \"%s\" failed", |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1650 tf->file.name.data); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1651 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1652 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1653 } |
4385
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
1654 |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
1655 if (c->wait_event.timer_set) { |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
1656 ngx_del_timer(&c->wait_event); |
70ba81827472
Cache locks initial implementation.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4340
diff
changeset
|
1657 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1658 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1659 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1660 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1661 static void |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1662 ngx_http_file_cache_cleanup(void *data) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1663 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1664 ngx_http_cache_t *c = data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1665 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1666 if (c->updated) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1667 return; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1668 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1669 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1670 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->file.log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1671 "http file cache cleanup"); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1672 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1673 if (c->updating) { |
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1674 ngx_log_error(NGX_LOG_ALERT, c->file.log, 0, |
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1675 "stalled cache updating, error:%ui", c->error); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1676 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1677 |
3711
ce6ba077c270
several changes in cache cleanup handling:
Igor Sysoev <igor@sysoev.ru>
parents:
3710
diff
changeset
|
1678 ngx_http_file_cache_free(c, NULL); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1679 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1680 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1681 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1682 static time_t |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1683 ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache) |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1684 { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1685 u_char *name; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1686 size_t len; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1687 time_t wait; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1688 ngx_uint_t tries; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1689 ngx_path_t *path; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1690 ngx_queue_t *q; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1691 ngx_http_file_cache_node_t *fcn; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1692 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1693 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1694 "http file cache forced expire"); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1695 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1696 path = cache->path; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1697 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1698 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1699 name = ngx_alloc(len + 1, ngx_cycle->log); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1700 if (name == NULL) { |
2694
49a1382b249b
set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents:
2693
diff
changeset
|
1701 return 10; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1702 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1703 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1704 ngx_memcpy(name, path->name.data, path->name.len); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1705 |
2694
49a1382b249b
set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents:
2693
diff
changeset
|
1706 wait = 10; |
3728 | 1707 tries = 20; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1708 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1709 ngx_shmtx_lock(&cache->shpool->mutex); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1710 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1711 for (q = ngx_queue_last(&cache->sh->queue); |
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1712 q != ngx_queue_sentinel(&cache->sh->queue); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1713 q = ngx_queue_prev(q)) |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1714 { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1715 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1716 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1717 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1718 "http file cache forced expire: #%d %d %02xd%02xd%02xd%02xd", |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1719 fcn->count, fcn->exists, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1720 fcn->key[0], fcn->key[1], fcn->key[2], fcn->key[3]); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1721 |
3727 | 1722 if (fcn->count == 0) { |
1723 ngx_http_file_cache_delete(cache, q, name); | |
3885 | 1724 wait = 0; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1725 |
3727 | 1726 } else { |
3728 | 1727 if (--tries) { |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1728 continue; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1729 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1730 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1731 wait = 1; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1732 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1733 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1734 break; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1735 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1736 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1737 ngx_shmtx_unlock(&cache->shpool->mutex); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1738 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1739 ngx_free(name); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1740 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1741 return wait; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1742 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1743 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1744 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1745 static time_t |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1746 ngx_http_file_cache_expire(ngx_http_file_cache_t *cache) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1747 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1748 u_char *name, *p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1749 size_t len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1750 time_t now, wait; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1751 ngx_path_t *path; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1752 ngx_queue_t *q; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1753 ngx_http_file_cache_node_t *fcn; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1754 u_char key[2 * NGX_HTTP_CACHE_KEY_LEN]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1755 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1756 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1757 "http file cache expire"); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1758 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1759 path = cache->path; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1760 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1761 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1762 name = ngx_alloc(len + 1, ngx_cycle->log); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1763 if (name == NULL) { |
2694
49a1382b249b
set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents:
2693
diff
changeset
|
1764 return 10; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1765 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1766 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1767 ngx_memcpy(name, path->name.data, path->name.len); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1768 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1769 now = ngx_time(); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1770 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1771 ngx_shmtx_lock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1772 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1773 for ( ;; ) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1774 |
5679
5748ce74c1cc
Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5441
diff
changeset
|
1775 if (ngx_quit || ngx_terminate) { |
5748ce74c1cc
Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5441
diff
changeset
|
1776 wait = 1; |
5748ce74c1cc
Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5441
diff
changeset
|
1777 break; |
5748ce74c1cc
Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5441
diff
changeset
|
1778 } |
5748ce74c1cc
Cache: added ngx_quit check to ngx_http_file_cache_expire().
Maxim Dounin <mdounin@mdounin.ru>
parents:
5441
diff
changeset
|
1779 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1780 if (ngx_queue_empty(&cache->sh->queue)) { |
2694
49a1382b249b
set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents:
2693
diff
changeset
|
1781 wait = 10; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1782 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1783 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1784 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1785 q = ngx_queue_last(&cache->sh->queue); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1786 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1787 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1788 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1789 wait = fcn->expire - now; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1790 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1791 if (wait > 0) { |
2694
49a1382b249b
set cache manager maximum sleep time to 10s
Igor Sysoev <igor@sysoev.ru>
parents:
2693
diff
changeset
|
1792 wait = wait > 10 ? 10 : wait; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1793 break; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1794 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1795 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1796 ngx_log_debug6(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1797 "http file cache expire: #%d %d %02xd%02xd%02xd%02xd", |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1798 fcn->count, fcn->exists, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1799 fcn->key[0], fcn->key[1], fcn->key[2], fcn->key[3]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1800 |
3727 | 1801 if (fcn->count == 0) { |
1802 ngx_http_file_cache_delete(cache, q, name); | |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1803 continue; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1804 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1805 |
3755
76e3a93821b1
fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents:
3744
diff
changeset
|
1806 if (fcn->deleting) { |
3942
2e8dbd773d63
fix r3756: release lock to allow other process to delete cache node
Igor Sysoev <igor@sysoev.ru>
parents:
3917
diff
changeset
|
1807 wait = 1; |
2e8dbd773d63
fix r3756: release lock to allow other process to delete cache node
Igor Sysoev <igor@sysoev.ru>
parents:
3917
diff
changeset
|
1808 break; |
3755
76e3a93821b1
fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents:
3744
diff
changeset
|
1809 } |
76e3a93821b1
fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents:
3744
diff
changeset
|
1810 |
3727 | 1811 p = ngx_hex_dump(key, (u_char *) &fcn->node.key, |
1812 sizeof(ngx_rbtree_key_t)); | |
1813 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t); | |
1814 (void) ngx_hex_dump(p, fcn->key, len); | |
1815 | |
1816 /* | |
1817 * abnormally exited workers may leave locked cache entries, | |
1818 * and although it may be safe to remove them completely, | |
4340
4533d7684e14
Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4339
diff
changeset
|
1819 * we prefer to just move them to the top of the inactive queue |
3727 | 1820 */ |
1821 | |
1822 ngx_queue_remove(q); | |
4340
4533d7684e14
Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4339
diff
changeset
|
1823 fcn->expire = ngx_time() + cache->inactive; |
4533d7684e14
Cache: only complain on long locked entries.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4339
diff
changeset
|
1824 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue); |
3727 | 1825 |
1826 ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0, | |
1827 "ignore long locked inactive cache entry %*s, count:%d", | |
1828 2 * NGX_HTTP_CACHE_KEY_LEN, key, fcn->count); | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1829 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1830 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1831 ngx_shmtx_unlock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1832 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1833 ngx_free(name); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1834 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1835 return wait; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1836 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1837 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1838 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1839 static void |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1840 ngx_http_file_cache_delete(ngx_http_file_cache_t *cache, ngx_queue_t *q, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1841 u_char *name) |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1842 { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1843 u_char *p; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1844 size_t len; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1845 ngx_path_t *path; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1846 ngx_http_file_cache_node_t *fcn; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1847 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1848 fcn = ngx_queue_data(q, ngx_http_file_cache_node_t, queue); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1849 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1850 if (fcn->exists) { |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
1851 cache->sh->size -= fcn->fs_size; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1852 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1853 path = cache->path; |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1854 p = name + path->name.len + 1 + path->len; |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1855 p = ngx_hex_dump(p, (u_char *) &fcn->node.key, |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1856 sizeof(ngx_rbtree_key_t)); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1857 len = NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1858 p = ngx_hex_dump(p, fcn->key, len); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1859 *p = '\0'; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1860 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1861 fcn->count++; |
3755
76e3a93821b1
fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents:
3744
diff
changeset
|
1862 fcn->deleting = 1; |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1863 ngx_shmtx_unlock(&cache->shpool->mutex); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1864 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1865 len = path->name.len + 1 + path->len + 2 * NGX_HTTP_CACHE_KEY_LEN; |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1866 ngx_create_hashed_filename(path, name, len); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1867 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1868 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1869 "http file cache expire: \"%s\"", name); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1870 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1871 if (ngx_delete_file(name) == NGX_FILE_ERROR) { |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1872 ngx_log_error(NGX_LOG_CRIT, ngx_cycle->log, ngx_errno, |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1873 ngx_delete_file_n " \"%s\" failed", name); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1874 } |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1875 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1876 ngx_shmtx_lock(&cache->shpool->mutex); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1877 fcn->count--; |
3755
76e3a93821b1
fix race condition if during reconfiguration two cache managers try
Igor Sysoev <igor@sysoev.ru>
parents:
3744
diff
changeset
|
1878 fcn->deleting = 0; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1879 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1880 |
3726
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1881 if (fcn->count == 0) { |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1882 ngx_queue_remove(q); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1883 ngx_rbtree_delete(&cache->sh->rbtree, &fcn->node); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1884 ngx_slab_free_locked(cache->shpool, fcn); |
282ddd49f925
*) delete cache key node after a cache file removal
Igor Sysoev <igor@sysoev.ru>
parents:
3724
diff
changeset
|
1885 } |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1886 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1887 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1888 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1889 static time_t |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1890 ngx_http_file_cache_manager(void *data) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1891 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1892 ngx_http_file_cache_t *cache = data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1893 |
3018 | 1894 off_t size; |
3885 | 1895 time_t next, wait; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1896 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1897 next = ngx_http_file_cache_expire(cache); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1898 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1899 cache->last = ngx_current_msec; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1900 cache->files = 0; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1901 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1902 for ( ;; ) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1903 ngx_shmtx_lock(&cache->shpool->mutex); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1904 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
1905 size = cache->sh->size; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1906 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1907 ngx_shmtx_unlock(&cache->shpool->mutex); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1908 |
2631 | 1909 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
1910 "http file cache size: %O", size); | |
1911 | |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1912 if (size < cache->max_size) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1913 return next; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1914 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1915 |
3885 | 1916 wait = ngx_http_file_cache_forced_expire(cache); |
1917 | |
1918 if (wait > 0) { | |
1919 return wait; | |
1920 } | |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1921 |
3972
c1a69e03bdf2
rename ngx_http_file_cache_manager_sleep() to ngx_http_file_cache_loader_sleep()
Igor Sysoev <igor@sysoev.ru>
parents:
3971
diff
changeset
|
1922 if (ngx_quit || ngx_terminate) { |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1923 return next; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1924 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1925 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1926 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1927 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1928 |
3018 | 1929 static void |
1930 ngx_http_file_cache_loader(void *data) | |
1931 { | |
1932 ngx_http_file_cache_t *cache = data; | |
1933 | |
1934 ngx_tree_ctx_t tree; | |
1935 | |
1936 if (!cache->sh->cold || cache->sh->loading) { | |
1937 return; | |
1938 } | |
1939 | |
1940 if (!ngx_atomic_cmp_set(&cache->sh->loading, 0, ngx_pid)) { | |
1941 return; | |
1942 } | |
1943 | |
1944 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, | |
1945 "http file cache loader"); | |
1946 | |
1947 tree.init_handler = NULL; | |
1948 tree.file_handler = ngx_http_file_cache_manage_file; | |
5968
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
1949 tree.pre_tree_handler = ngx_http_file_cache_manage_directory; |
3018 | 1950 tree.post_tree_handler = ngx_http_file_cache_noop; |
1951 tree.spec_handler = ngx_http_file_cache_delete_file; | |
1952 tree.data = cache; | |
1953 tree.alloc = 0; | |
1954 tree.log = ngx_cycle->log; | |
1955 | |
1956 cache->last = ngx_current_msec; | |
1957 cache->files = 0; | |
1958 | |
1959 if (ngx_walk_tree(&tree, &cache->path->name) == NGX_ABORT) { | |
3020
364ea8f54a2f
unlock incompletely loaded cache
Igor Sysoev <igor@sysoev.ru>
parents:
3018
diff
changeset
|
1960 cache->sh->loading = 0; |
3018 | 1961 return; |
1962 } | |
1963 | |
1964 cache->sh->cold = 0; | |
1965 cache->sh->loading = 0; | |
1966 | |
1967 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, | |
1968 "http file cache: %V %.3fM, bsize: %uz", | |
1969 &cache->path->name, | |
1970 ((double) cache->sh->size * cache->bsize) / (1024 * 1024), | |
1971 cache->bsize); | |
1972 } | |
1973 | |
1974 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1975 static ngx_int_t |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1976 ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1977 { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1978 return NGX_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1979 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1980 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1981 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1982 static ngx_int_t |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1983 ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path) |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
1984 { |
4018
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1985 ngx_msec_t elapsed; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1986 ngx_http_file_cache_t *cache; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1987 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1988 cache = ctx->data; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1989 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1990 if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1991 (void) ngx_http_file_cache_delete_file(ctx, path); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1992 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
1993 |
4018
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1994 if (++cache->files >= cache->loader_files) { |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1995 ngx_http_file_cache_loader_sleep(cache); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1996 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1997 } else { |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1998 ngx_time_update(); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
1999 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2000 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last)); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2001 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2002 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2003 "http file cache loader time elapsed: %M", elapsed); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2004 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2005 if (elapsed >= cache->loader_threshold) { |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2006 ngx_http_file_cache_loader_sleep(cache); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2007 } |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2008 } |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2009 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2010 return (ngx_quit || ngx_terminate) ? NGX_ABORT : NGX_OK; |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2011 } |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2012 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2013 |
5968
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2014 static ngx_int_t |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2015 ngx_http_file_cache_manage_directory(ngx_tree_ctx_t *ctx, ngx_str_t *path) |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2016 { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2017 if (path->len >= 5 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2018 && ngx_strncmp(path->data + path->len - 5, "/temp", 5) == 0) |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2019 { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2020 return NGX_DECLINED; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2021 } |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2022 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2023 return NGX_OK; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2024 } |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2025 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2026 |
4018
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2027 static void |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2028 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache) |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2029 { |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2030 ngx_msleep(cache->loader_sleep); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2031 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2032 ngx_time_update(); |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2033 |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2034 cache->last = ngx_current_msec; |
5e544655d97b
The change in adaptive loader behaviour introduced in r3975:
Igor Sysoev <igor@sysoev.ru>
parents:
3974
diff
changeset
|
2035 cache->files = 0; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2036 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2037 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2038 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2039 static ngx_int_t |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2040 ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name) |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2041 { |
3970
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2042 u_char *p; |
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2043 ngx_int_t n; |
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2044 ngx_uint_t i; |
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2045 ngx_http_cache_t c; |
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2046 ngx_http_file_cache_t *cache; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2047 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2048 if (name->len < 2 * NGX_HTTP_CACHE_KEY_LEN) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2049 return NGX_ERROR; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2050 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2051 |
3970
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2052 if (ctx->size < (off_t) sizeof(ngx_http_file_cache_header_t)) { |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2053 ngx_log_error(NGX_LOG_CRIT, ctx->log, 0, |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2054 "cache file \"%s\" is too small", name->data); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2055 return NGX_ERROR; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2056 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2057 |
3970
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2058 ngx_memzero(&c, sizeof(ngx_http_cache_t)); |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
2059 cache = ctx->data; |
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
2060 |
3970
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2061 c.length = ctx->size; |
2d05952a324d
elimination of reading cache files by cache loader
Igor Sysoev <igor@sysoev.ru>
parents:
3969
diff
changeset
|
2062 c.fs_size = (ctx->fs_size + cache->bsize - 1) / cache->bsize; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2063 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2064 p = &name->data[name->len - 2 * NGX_HTTP_CACHE_KEY_LEN]; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2065 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2066 for (i = 0; i < NGX_HTTP_CACHE_KEY_LEN; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2067 n = ngx_hextoi(p, 2); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2068 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2069 if (n == NGX_ERROR) { |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2070 return NGX_ERROR; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2071 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2072 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2073 p += 2; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2074 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2075 c.key[i] = (u_char) n; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2076 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2077 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2078 return ngx_http_file_cache_add(cache, &c); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2079 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2080 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2081 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2082 static ngx_int_t |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2083 ngx_http_file_cache_add(ngx_http_file_cache_t *cache, ngx_http_cache_t *c) |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2084 { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2085 ngx_http_file_cache_node_t *fcn; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2086 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2087 ngx_shmtx_lock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2088 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2089 fcn = ngx_http_file_cache_lookup(cache, c->key); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2090 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2091 if (fcn == NULL) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2092 |
5726
25ade23cf281
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents:
5679
diff
changeset
|
2093 fcn = ngx_slab_calloc_locked(cache->shpool, |
25ade23cf281
Core: added ngx_slab_calloc() and ngx_slab_calloc_locked().
Ruslan Ermilov <ru@nginx.com>
parents:
5679
diff
changeset
|
2094 sizeof(ngx_http_file_cache_node_t)); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2095 if (fcn == NULL) { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2096 ngx_shmtx_unlock(&cache->shpool->mutex); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2097 return NGX_ERROR; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2098 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2099 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2100 ngx_memcpy((u_char *) &fcn->node.key, c->key, sizeof(ngx_rbtree_key_t)); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2101 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2102 ngx_memcpy(fcn->key, &c->key[sizeof(ngx_rbtree_key_t)], |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2103 NGX_HTTP_CACHE_KEY_LEN - sizeof(ngx_rbtree_key_t)); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2104 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
2105 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node); |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2106 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2107 fcn->uses = 1; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2108 fcn->exists = 1; |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
2109 fcn->fs_size = c->fs_size; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2110 |
3899
e7cd13b7f759
Use more precise stat.st_blocks to account cache size on Unix
Igor Sysoev <igor@sysoev.ru>
parents:
3885
diff
changeset
|
2111 cache->sh->size += c->fs_size; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2112 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2113 } else { |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2114 ngx_queue_remove(&fcn->queue); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2115 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2116 |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2117 fcn->expire = ngx_time() + cache->inactive; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2118 |
2720
b3b8c66bd520
support attaching to an existent Win32 shared memory
Igor Sysoev <igor@sysoev.ru>
parents:
2716
diff
changeset
|
2119 ngx_queue_insert_head(&cache->sh->queue, &fcn->queue); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2120 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2121 ngx_shmtx_unlock(&cache->shpool->mutex); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2122 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2123 return NGX_OK; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2124 } |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2125 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2126 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2127 static ngx_int_t |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2128 ngx_http_file_cache_delete_file(ngx_tree_ctx_t *ctx, ngx_str_t *path) |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2129 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2130 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->log, 0, |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2131 "http file cache delete: \"%s\"", path->data); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2132 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2133 if (ngx_delete_file(path->data) == NGX_FILE_ERROR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2134 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2135 ngx_delete_file_n " \"%s\" failed", path->data); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2136 } |
477 | 2137 |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2138 return NGX_OK; |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2139 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2140 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2141 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2142 time_t |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2143 ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status) |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2144 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2145 ngx_uint_t i; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2146 ngx_http_cache_valid_t *valid; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2147 |
2626
b0cfe5f66e8d
fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
2148 if (cache_valid == NULL) { |
b0cfe5f66e8d
fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
2149 return 0; |
b0cfe5f66e8d
fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
2150 } |
b0cfe5f66e8d
fix segfault introduced in r2602 if there is 502/504 error
Igor Sysoev <igor@sysoev.ru>
parents:
2616
diff
changeset
|
2151 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2152 valid = cache_valid->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2153 for (i = 0; i < cache_valid->nelts; i++) { |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2154 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2155 if (valid[i].status == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2156 return valid[i].valid; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2157 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2158 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2159 if (valid[i].status == status) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2160 return valid[i].valid; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2161 } |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2162 } |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2163 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2164 return 0; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2165 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2166 |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2167 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2168 char * |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2169 ngx_http_file_cache_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2170 { |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2171 char *confp = conf; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2172 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2173 off_t max_size; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2174 u_char *last, *p; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2175 time_t inactive; |
5968
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2176 size_t len; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2177 ssize_t size; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2178 ngx_str_t s, name, *value; |
4474 | 2179 ngx_int_t loader_files; |
2180 ngx_msec_t loader_sleep, loader_threshold; | |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2181 ngx_uint_t i, n, use_temp_path; |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2182 ngx_array_t *caches; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2183 ngx_http_file_cache_t *cache, **ce; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2184 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2185 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2186 if (cache == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2187 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2188 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2189 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2190 cache->path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2191 if (cache->path == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2192 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2193 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2194 |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2195 use_temp_path = 1; |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2196 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2197 inactive = 600; |
3974
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2198 loader_files = 100; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2199 loader_sleep = 50; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2200 loader_threshold = 200; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2201 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2202 name.len = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2203 size = 0; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2204 max_size = NGX_MAX_OFF_T_VALUE; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2205 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2206 value = cf->args->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2207 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2208 cache->path->name = value[1]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2209 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2210 if (cache->path->name.data[cache->path->name.len - 1] == '/') { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2211 cache->path->name.len--; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2212 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2213 |
5330
314c3d7cc3a5
Backed out f1a91825730a and 7094bd12c1ff.
Maxim Dounin <mdounin@mdounin.ru>
parents:
5317
diff
changeset
|
2214 if (ngx_conf_full_name(cf->cycle, &cache->path->name, 0) != NGX_OK) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2215 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2216 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2217 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2218 for (i = 2; i < cf->args->nelts; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2219 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2220 if (ngx_strncmp(value[i].data, "levels=", 7) == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2221 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2222 p = value[i].data + 7; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2223 last = value[i].data + value[i].len; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2224 |
2671 | 2225 for (n = 0; n < 3 && p < last; n++) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2226 |
2671 | 2227 if (*p > '0' && *p < '3') { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2228 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2229 cache->path->level[n] = *p++ - '0'; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2230 cache->path->len += cache->path->level[n] + 1; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2231 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2232 if (p == last) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2233 break; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2234 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2235 |
2671 | 2236 if (*p++ == ':' && n < 2 && p != last) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2237 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2238 } |
2671 | 2239 |
2240 goto invalid_levels; | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2241 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2242 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2243 goto invalid_levels; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2244 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2245 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2246 if (cache->path->len < 10 + 3) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2247 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2248 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2249 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2250 invalid_levels: |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2251 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2252 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2253 "invalid \"levels\" \"%V\"", &value[i]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2254 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2255 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2256 |
5960
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2257 if (ngx_strncmp(value[i].data, "use_temp_path=", 14) == 0) { |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2258 |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2259 if (ngx_strcmp(&value[i].data[14], "on") == 0) { |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2260 use_temp_path = 1; |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2261 |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2262 } else if (ngx_strcmp(&value[i].data[14], "off") == 0) { |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2263 use_temp_path = 0; |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2264 |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2265 } else { |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2266 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2267 "invalid use_temp_path value \"%V\", " |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2268 "it must be \"on\" or \"off\"", |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2269 &value[i]); |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2270 return NGX_CONF_ERROR; |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2271 } |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2272 |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2273 continue; |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2274 } |
e9effef98874
Upstream: use_temp_path parameter of proxy_cache_path and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5959
diff
changeset
|
2275 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2276 if (ngx_strncmp(value[i].data, "keys_zone=", 10) == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2277 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2278 name.data = value[i].data + 10; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2279 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2280 p = (u_char *) ngx_strchr(name.data, ':'); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2281 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2282 if (p) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2283 name.len = p - name.data; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2284 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2285 p++; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2286 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2287 s.len = value[i].data + value[i].len - p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2288 s.data = p; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2289 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2290 size = ngx_parse_size(&s); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2291 if (size > 8191) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2292 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2293 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2294 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2295 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2296 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2297 "invalid keys zone size \"%V\"", &value[i]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2298 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2299 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2300 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2301 if (ngx_strncmp(value[i].data, "inactive=", 9) == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2302 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2303 s.len = value[i].len - 9; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2304 s.data = value[i].data + 9; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2305 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2306 inactive = ngx_parse_time(&s, 1); |
4474 | 2307 if (inactive == (time_t) NGX_ERROR) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2308 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2309 "invalid inactive value \"%V\"", &value[i]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2310 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2311 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2312 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2313 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2314 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2315 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2316 if (ngx_strncmp(value[i].data, "max_size=", 9) == 0) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2317 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2318 s.len = value[i].len - 9; |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2319 s.data = value[i].data + 9; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2320 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2321 max_size = ngx_parse_offset(&s); |
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2322 if (max_size < 0) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2323 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2324 "invalid max_size value \"%V\"", &value[i]); |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2325 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2326 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2327 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2328 continue; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2329 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2330 |
3974
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2331 if (ngx_strncmp(value[i].data, "loader_files=", 13) == 0) { |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2332 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2333 loader_files = ngx_atoi(value[i].data + 13, value[i].len - 13); |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2334 if (loader_files == NGX_ERROR) { |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2335 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2336 "invalid loader_files value \"%V\"", &value[i]); |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2337 return NGX_CONF_ERROR; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2338 } |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2339 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2340 continue; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2341 } |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2342 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2343 if (ngx_strncmp(value[i].data, "loader_sleep=", 13) == 0) { |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2344 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2345 s.len = value[i].len - 13; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2346 s.data = value[i].data + 13; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2347 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2348 loader_sleep = ngx_parse_time(&s, 0); |
4474 | 2349 if (loader_sleep == (ngx_msec_t) NGX_ERROR) { |
3974
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2350 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2351 "invalid loader_sleep value \"%V\"", &value[i]); |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2352 return NGX_CONF_ERROR; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2353 } |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2354 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2355 continue; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2356 } |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2357 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2358 if (ngx_strncmp(value[i].data, "loader_threshold=", 17) == 0) { |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2359 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2360 s.len = value[i].len - 17; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2361 s.data = value[i].data + 17; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2362 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2363 loader_threshold = ngx_parse_time(&s, 0); |
4474 | 2364 if (loader_threshold == (ngx_msec_t) NGX_ERROR) { |
3974
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2365 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2366 "invalid loader_threshold value \"%V\"", &value[i]); |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2367 return NGX_CONF_ERROR; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2368 } |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2369 |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2370 continue; |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2371 } |
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2372 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2373 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2374 "invalid parameter \"%V\"", &value[i]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2375 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2376 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2377 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2378 if (name.len == 0 || size == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2379 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2380 "\"%V\" must have \"keys_zone\" parameter", |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2381 &cmd->name); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2382 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2383 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2384 |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2385 cache->path->manager = ngx_http_file_cache_manager; |
3018 | 2386 cache->path->loader = ngx_http_file_cache_loader; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2387 cache->path->data = cache; |
3973
9d6f21415231
set correct configuration file values while adding path
Igor Sysoev <igor@sysoev.ru>
parents:
3972
diff
changeset
|
2388 cache->path->conf_file = cf->conf_file->file.name.data; |
9d6f21415231
set correct configuration file values while adding path
Igor Sysoev <igor@sysoev.ru>
parents:
3972
diff
changeset
|
2389 cache->path->line = cf->conf_file->line; |
3974
d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
Igor Sysoev <igor@sysoev.ru>
parents:
3973
diff
changeset
|
2390 cache->loader_files = loader_files; |
4474 | 2391 cache->loader_sleep = loader_sleep; |
2392 cache->loader_threshold = loader_threshold; | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2393 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2394 if (ngx_add_path(cf, &cache->path) != NGX_OK) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2395 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2396 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2397 |
5968
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2398 if (!use_temp_path) { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2399 cache->temp_path = ngx_pcalloc(cf->pool, sizeof(ngx_path_t)); |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2400 if (cache->temp_path == NULL) { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2401 return NGX_CONF_ERROR; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2402 } |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2403 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2404 len = cache->path->name.len + sizeof("/temp") - 1; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2405 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2406 p = ngx_pnalloc(cf->pool, len + 1); |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2407 if (p == NULL) { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2408 return NGX_CONF_ERROR; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2409 } |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2410 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2411 cache->temp_path->name.len = len; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2412 cache->temp_path->name.data = p; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2413 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2414 p = ngx_cpymem(p, cache->path->name.data, cache->path->name.len); |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2415 ngx_memcpy(p, "/temp", sizeof("/temp")); |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2416 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2417 ngx_memcpy(&cache->temp_path->level, &cache->path->level, |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2418 3 * sizeof(size_t)); |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2419 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2420 cache->temp_path->len = cache->path->len; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2421 cache->temp_path->conf_file = cf->conf_file->file.name.data; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2422 cache->temp_path->line = cf->conf_file->line; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2423 |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2424 if (ngx_add_path(cf, &cache->temp_path) != NGX_OK) { |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2425 return NGX_CONF_ERROR; |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2426 } |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2427 } |
99639bfdfa2a
Cache: added temp_path to file cache.
Roman Arutyunyan <arut@nginx.com>
parents:
5960
diff
changeset
|
2428 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2429 cache->shm_zone = ngx_shared_memory_add(cf, &name, size, cmd->post); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2430 if (cache->shm_zone == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2431 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2432 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2433 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2434 if (cache->shm_zone->data) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2435 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2436 "duplicate zone \"%V\"", &name); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2437 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2438 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2439 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2440 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2441 cache->shm_zone->init = ngx_http_file_cache_init; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2442 cache->shm_zone->data = cache; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2443 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2444 cache->inactive = inactive; |
2616
d19979e0d980
introduce cache manager instead of cache cleaner
Igor Sysoev <igor@sysoev.ru>
parents:
2611
diff
changeset
|
2445 cache->max_size = max_size; |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2446 |
5951
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2447 caches = (ngx_array_t *) (confp + cmd->offset); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2448 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2449 ce = ngx_array_push(caches); |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2450 if (ce == NULL) { |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2451 return NGX_CONF_ERROR; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2452 } |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2453 |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2454 *ce = cache; |
610832763648
Upstream: added variables support to proxy_cache and friends.
Valentin Bartenev <vbart@nginx.com>
parents:
5935
diff
changeset
|
2455 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2456 return NGX_CONF_OK; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2457 } |
477 | 2458 |
2459 | |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2460 char * |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2461 ngx_http_file_cache_valid_set_slot(ngx_conf_t *cf, ngx_command_t *cmd, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2462 void *conf) |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2463 { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2464 char *p = conf; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2465 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2466 time_t valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2467 ngx_str_t *value; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2468 ngx_uint_t i, n, status; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2469 ngx_array_t **a; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2470 ngx_http_cache_valid_t *v; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2471 static ngx_uint_t statuses[] = { 200, 301, 302 }; |
477 | 2472 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2473 a = (ngx_array_t **) (p + cmd->offset); |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2474 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2475 if (*a == NGX_CONF_UNSET_PTR) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2476 *a = ngx_array_create(cf->pool, 1, sizeof(ngx_http_cache_valid_t)); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2477 if (*a == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2478 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2479 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2480 } |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2481 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2482 value = cf->args->elts; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2483 n = cf->args->nelts - 1; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2484 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2485 valid = ngx_parse_time(&value[n], 1); |
4474 | 2486 if (valid == (time_t) NGX_ERROR) { |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2487 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2488 "invalid time value \"%V\"", &value[n]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2489 return NGX_CONF_ERROR; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2490 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2491 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2492 if (n == 1) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2493 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2494 for (i = 0; i < 3; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2495 v = ngx_array_push(*a); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2496 if (v == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2497 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2498 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2499 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2500 v->status = statuses[i]; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2501 v->valid = valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2502 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2503 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2504 return NGX_CONF_OK; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2505 } |
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2506 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2507 for (i = 1; i < n; i++) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2508 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2509 if (ngx_strcmp(value[i].data, "any") == 0) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2510 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2511 status = 0; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2512 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2513 } else { |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2514 |
2592
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2515 status = ngx_atoi(value[i].data, value[i].len); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2516 if (status < 100) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2517 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2518 "invalid status \"%V\"", &value[i]); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2519 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2520 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2521 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2522 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2523 v = ngx_array_push(*a); |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2524 if (v == NULL) { |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2525 return NGX_CONF_ERROR; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2526 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2527 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2528 v->status = status; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2529 v->valid = valid; |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2530 } |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2531 |
3a8a53c0c42f
a prelimiary proxy cache support
Igor Sysoev <igor@sysoev.ru>
parents:
633
diff
changeset
|
2532 return NGX_CONF_OK; |
202
74994aeef848
nginx-0.0.1-2003-12-01-19:28:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
2533 } |