Mercurial > hg > nginx
comparison src/http/ngx_http_cache.c @ 97:70d2345a903f
nginx-0.0.1-2003-05-29-17:02:09 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 29 May 2003 13:02:09 +0000 |
parents | |
children | a059e1aa65d4 |
comparison
equal
deleted
inserted
replaced
96:a23d010f356d | 97:70d2345a903f |
---|---|
1 | |
2 | |
3 | |
4 #define NGX_HTTP_CACHE_ENTRY_DELETED 0x00000001 | |
5 #define NGX_HTTP_CACHE_ENTRY_MMAPED 0x00000002 | |
6 | |
7 /* "/" -> "/index.html" in ngx_http_index_handler */ | |
8 #define NGX_HTTP_CACHE_ENTRY_URI 0x00000004 | |
9 | |
10 #define NGX_HTTP_CACHE_FILTER_FLAGS 0xFFFF0000 | |
11 | |
12 | |
13 typedef struct { | |
14 ngx_fd_t fd; | |
15 off_t size; | |
16 void *data; | |
17 time_t accessed; | |
18 time_t last_modified; | |
19 time_t updated; /* no needed with kqueue */ | |
20 int refs; | |
21 int flags; | |
22 } ngx_http_cache_entry_t; | |
23 | |
24 | |
25 typedef struct { | |
26 u_int32_t crc; | |
27 ngx_str_t uri; | |
28 ngx_http_cache_t *cache; | |
29 } ngx_http_cache_hash_entry_t; | |
30 | |
31 | |
32 typedef struct { | |
33 ngx_http_cache_t *cache; | |
34 u_int32_t crc; | |
35 int n; | |
36 } ngx_http_cache_handle_t; | |
37 | |
38 | |
39 int ngx_http_cache_get(ngx_http_cache_hash_t *cache_hash, | |
40 ngx_str_t *uri, ngx_http_cache_handle_t *h) | |
41 { | |
42 int hi; | |
43 ngx_http_cache_hash_entry_t *entry; | |
44 | |
45 h->crc = ngx_crc32(uri->data, uri->len); | |
46 | |
47 hi = h->crc % cache_hash->size; | |
48 entry = cache_hash[hi].elts; | |
49 | |
50 for (i = 0; i < cache_hash[hi].nelts; i++) { | |
51 if (entry[i].crc == crc | |
52 && entry[i].uri.len == uri->len | |
53 && ngx_strncmp(entry[i].uri.data, uri->data, uri->len) == 0 | |
54 { | |
55 h->cache = entry[i].cache; | |
56 h->cache->refs++; | |
57 h->n = hi; | |
58 return NGX_OK; | |
59 } | |
60 } | |
61 | |
62 return NGX_ERROR; | |
63 } |