diff options
author | Lars Hjemli <hjemli@gmail.com> | 2006-12-11 06:31:36 (JST) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2006-12-11 06:31:36 (JST) |
commit | 25105d7ecaba474d4b7c364ebb586aac3dfc5abb (patch) | |
tree | 8beb08db1399b8efb8c7fbcd936044ae7fc232e6 /cgit.h | |
parent | 856c026e221d8ed82c5b75bc8da4bd65e89ea953 (diff) | |
download | cgit-25105d7ecaba474d4b7c364ebb586aac3dfc5abb.zip cgit-25105d7ecaba474d4b7c364ebb586aac3dfc5abb.tar.gz |
Add caching infrastructure
This enables internal caching of page output.
Page requests are split into four groups:
1) repo listing (front page)
2) repo summary
3) repo pages w/symbolic references in query string
4) repo pages w/constant sha1's in query string
Each group has a TTL specified in minutes. When a page is requested, a cached
filename is stat(2)'ed and st_mtime is compared to time(2). If TTL has expired
(or the file didn't exist), the cached file is regenerated.
When generating a cached file, locking is used to avoid parallell processing
of the request. If multiple processes tries to aquire the same lock, the ones
who fail to get the lock serves the (expired) cached file. If the cached file
don't exist, the process instead calls sched_yield(2) before restarting the
request processing.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Diffstat (limited to 'cgit.h')
-rw-r--r-- | cgit.h | 47 |
1 files changed, 45 insertions, 2 deletions
@@ -3,6 +3,46 @@ | |||
3 | 3 | ||
4 | #include "git.h" | 4 | #include "git.h" |
5 | #include <openssl/sha.h> | 5 | #include <openssl/sha.h> |
6 | #include <ctype.h> | ||
7 | #include <sched.h> | ||
8 | |||
9 | typedef void (*configfn)(const char *name, const char *value); | ||
10 | |||
11 | struct cacheitem { | ||
12 | char *name; | ||
13 | struct stat st; | ||
14 | int ttl; | ||
15 | int fd; | ||
16 | }; | ||
17 | |||
18 | extern char *cgit_root; | ||
19 | extern char *cgit_root_title; | ||
20 | extern char *cgit_css; | ||
21 | extern char *cgit_logo; | ||
22 | extern char *cgit_logo_link; | ||
23 | extern char *cgit_virtual_root; | ||
24 | extern char *cgit_cache_root; | ||
25 | |||
26 | extern int cgit_cache_root_ttl; | ||
27 | extern int cgit_cache_repo_ttl; | ||
28 | extern int cgit_cache_dynamic_ttl; | ||
29 | extern int cgit_cache_static_ttl; | ||
30 | extern int cgit_cache_max_create_time; | ||
31 | |||
32 | extern char *cgit_repo_name; | ||
33 | extern char *cgit_repo_desc; | ||
34 | extern char *cgit_repo_owner; | ||
35 | |||
36 | extern int cgit_query_has_symref; | ||
37 | extern int cgit_query_has_sha1; | ||
38 | |||
39 | extern char *cgit_querystring; | ||
40 | extern char *cgit_query_repo; | ||
41 | extern char *cgit_query_page; | ||
42 | extern char *cgit_query_head; | ||
43 | extern char *cgit_query_sha1; | ||
44 | |||
45 | extern int htmlfd; | ||
6 | 46 | ||
7 | extern char *fmt(const char *format,...); | 47 | extern char *fmt(const char *format,...); |
8 | 48 | ||
@@ -10,12 +50,15 @@ extern void html(const char *txt); | |||
10 | extern void htmlf(const char *format,...); | 50 | extern void htmlf(const char *format,...); |
11 | extern void html_txt(char *txt); | 51 | extern void html_txt(char *txt); |
12 | extern void html_attr(char *txt); | 52 | extern void html_attr(char *txt); |
13 | |||
14 | extern void html_link_open(char *url, char *title, char *class); | 53 | extern void html_link_open(char *url, char *title, char *class); |
15 | extern void html_link_close(void); | 54 | extern void html_link_close(void); |
16 | 55 | ||
17 | typedef void (*configfn)(const char *name, const char *value); | ||
18 | 56 | ||
19 | extern int cgit_read_config(const char *filename, configfn fn); | 57 | extern int cgit_read_config(const char *filename, configfn fn); |
20 | 58 | ||
59 | extern int cache_lookup(struct cacheitem *item); | ||
60 | extern int cache_lock(struct cacheitem *item); | ||
61 | extern int cache_unlock(struct cacheitem *item); | ||
62 | extern int cache_expired(struct cacheitem *item); | ||
63 | |||
21 | #endif /* CGIT_H */ | 64 | #endif /* CGIT_H */ |