diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-05-28 23:33:30 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-08-13 04:14:10 (JST) |
commit | 61ff10065b579fa38182fcf10cc7e63839acd53c (patch) | |
tree | 0d4b37af5a034c10763f7d0f1c39af55fabed115 | |
parent | 23debef62104c70600be2b745ec3957538eeac6e (diff) | |
download | cgit-61ff10065b579fa38182fcf10cc7e63839acd53c.zip cgit-61ff10065b579fa38182fcf10cc7e63839acd53c.tar.gz |
cache: document negative ttls and add about ttl
We've long supported negative ttls, for infinite cache, except the
documentation incorrectly showed one of our defaults as being 5 and not
-1. As well, with a negative ttl, we were actually making the HTTP
expired header go backwards. This changes it to go ahead ten years
instead.
Further, we add an cache-about-ttl option to set a different ttl for
about pages, which are now increasingly being filtered through markdown
or just sent statically anyway.
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | cgit.c | 15 | ||||
-rw-r--r-- | cgit.h | 1 | ||||
-rw-r--r-- | cgitrc.5.txt | 28 |
3 files changed, 31 insertions, 13 deletions
@@ -211,6 +211,8 @@ static void config_cb(const char *name, const char *value) | |||
211 | ctx.cfg.cache_static_ttl = atoi(value); | 211 | ctx.cfg.cache_static_ttl = atoi(value); |
212 | else if (!strcmp(name, "cache-dynamic-ttl")) | 212 | else if (!strcmp(name, "cache-dynamic-ttl")) |
213 | ctx.cfg.cache_dynamic_ttl = atoi(value); | 213 | ctx.cfg.cache_dynamic_ttl = atoi(value); |
214 | else if (!strcmp(name, "cache-about-ttl")) | ||
215 | ctx.cfg.cache_about_ttl = atoi(value); | ||
214 | else if (!strcmp(name, "case-sensitive-sort")) | 216 | else if (!strcmp(name, "case-sensitive-sort")) |
215 | ctx.cfg.case_sensitive_sort = atoi(value); | 217 | ctx.cfg.case_sensitive_sort = atoi(value); |
216 | else if (!strcmp(name, "about-filter")) | 218 | else if (!strcmp(name, "about-filter")) |
@@ -351,12 +353,13 @@ static void prepare_context(struct cgit_context *ctx) | |||
351 | ctx->cfg.agefile = "info/web/last-modified"; | 353 | ctx->cfg.agefile = "info/web/last-modified"; |
352 | ctx->cfg.nocache = 0; | 354 | ctx->cfg.nocache = 0; |
353 | ctx->cfg.cache_size = 0; | 355 | ctx->cfg.cache_size = 0; |
354 | ctx->cfg.cache_dynamic_ttl = 5; | ||
355 | ctx->cfg.cache_max_create_time = 5; | 356 | ctx->cfg.cache_max_create_time = 5; |
356 | ctx->cfg.cache_repo_ttl = 5; | ||
357 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; | 357 | ctx->cfg.cache_root = CGIT_CACHE_ROOT; |
358 | ctx->cfg.cache_about_ttl = 15; | ||
359 | ctx->cfg.cache_repo_ttl = 5; | ||
358 | ctx->cfg.cache_root_ttl = 5; | 360 | ctx->cfg.cache_root_ttl = 5; |
359 | ctx->cfg.cache_scanrc_ttl = 15; | 361 | ctx->cfg.cache_scanrc_ttl = 15; |
362 | ctx->cfg.cache_dynamic_ttl = 5; | ||
360 | ctx->cfg.cache_static_ttl = -1; | 363 | ctx->cfg.cache_static_ttl = -1; |
361 | ctx->cfg.case_sensitive_sort = 1; | 364 | ctx->cfg.case_sensitive_sort = 1; |
362 | ctx->cfg.branch_sort = 0; | 365 | ctx->cfg.branch_sort = 0; |
@@ -922,6 +925,9 @@ static int calc_ttl() | |||
922 | if (!ctx.qry.page) | 925 | if (!ctx.qry.page) |
923 | return ctx.cfg.cache_repo_ttl; | 926 | return ctx.cfg.cache_repo_ttl; |
924 | 927 | ||
928 | if (!strcmp(ctx.qry.page, "about")) | ||
929 | return ctx.cfg.cache_about_ttl; | ||
930 | |||
925 | if (ctx.qry.has_symref) | 931 | if (ctx.qry.has_symref) |
926 | return ctx.cfg.cache_dynamic_ttl; | 932 | return ctx.cfg.cache_dynamic_ttl; |
927 | 933 | ||
@@ -973,7 +979,10 @@ int main(int argc, const char **argv) | |||
973 | } | 979 | } |
974 | 980 | ||
975 | ttl = calc_ttl(); | 981 | ttl = calc_ttl(); |
976 | ctx.page.expires += ttl * 60; | 982 | if (ttl < 0) |
983 | ctx.page.expires += 10 * 365 * 24 * 60 * 60; /* 10 years */ | ||
984 | else | ||
985 | ctx.page.expires += ttl * 60; | ||
977 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) | 986 | if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")) |
978 | ctx.cfg.nocache = 1; | 987 | ctx.cfg.nocache = 1; |
979 | if (ctx.cfg.nocache) | 988 | if (ctx.cfg.nocache) |
@@ -200,6 +200,7 @@ struct cgit_config { | |||
200 | int cache_root_ttl; | 200 | int cache_root_ttl; |
201 | int cache_scanrc_ttl; | 201 | int cache_scanrc_ttl; |
202 | int cache_static_ttl; | 202 | int cache_static_ttl; |
203 | int cache_about_ttl; | ||
203 | int case_sensitive_sort; | 204 | int case_sensitive_sort; |
204 | int embedded; | 205 | int embedded; |
205 | int enable_filter_overrides; | 206 | int enable_filter_overrides; |
diff --git a/cgitrc.5.txt b/cgitrc.5.txt index b4603ef..9d0c089 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt | |||
@@ -50,32 +50,40 @@ cache-root:: | |||
50 | Path used to store the cgit cache entries. Default value: | 50 | Path used to store the cgit cache entries. Default value: |
51 | "/var/cache/cgit". See also: "MACRO EXPANSION". | 51 | "/var/cache/cgit". See also: "MACRO EXPANSION". |
52 | 52 | ||
53 | cache-static-ttl:: | ||
54 | Number which specifies the time-to-live, in minutes, for the cached | ||
55 | version of repository pages accessed with a fixed SHA1. Negative | ||
56 | values have infinite ttl. Default value: -1". | ||
57 | |||
53 | cache-dynamic-ttl:: | 58 | cache-dynamic-ttl:: |
54 | Number which specifies the time-to-live, in minutes, for the cached | 59 | Number which specifies the time-to-live, in minutes, for the cached |
55 | version of repository pages accessed without a fixed SHA1. Default | 60 | version of repository pages accessed without a fixed SHA1. Negative |
56 | value: "5". | 61 | values have infinite ttl. Default value: "5". |
57 | 62 | ||
58 | cache-repo-ttl:: | 63 | cache-repo-ttl:: |
59 | Number which specifies the time-to-live, in minutes, for the cached | 64 | Number which specifies the time-to-live, in minutes, for the cached |
60 | version of the repository summary page. Default value: "5". | 65 | version of the repository summary page. Negative values have infinite |
66 | ttl. Default value: "5". | ||
61 | 67 | ||
62 | cache-root-ttl:: | 68 | cache-root-ttl:: |
63 | Number which specifies the time-to-live, in minutes, for the cached | 69 | Number which specifies the time-to-live, in minutes, for the cached |
64 | version of the repository index page. Default value: "5". | 70 | version of the repository index page. Negative values have infinite |
71 | ttl. Default value: "5". | ||
65 | 72 | ||
66 | cache-scanrc-ttl:: | 73 | cache-scanrc-ttl:: |
67 | Number which specifies the time-to-live, in minutes, for the result | 74 | Number which specifies the time-to-live, in minutes, for the result |
68 | of scanning a path for git repositories. Default value: "15". | 75 | of scanning a path for git repositories. Negative values have infinite |
76 | ttl. Default value: "15". | ||
77 | |||
78 | cache-about-ttl:: | ||
79 | Number which specifies the time-to-live, in minutes, for the cached | ||
80 | version of the repository about page. Negative values have infinite | ||
81 | ttl. Default value: "15". | ||
69 | 82 | ||
70 | cache-size:: | 83 | cache-size:: |
71 | The maximum number of entries in the cgit cache. Default value: "0" | 84 | The maximum number of entries in the cgit cache. Default value: "0" |
72 | (i.e. caching is disabled). | 85 | (i.e. caching is disabled). |
73 | 86 | ||
74 | cache-static-ttl:: | ||
75 | Number which specifies the time-to-live, in minutes, for the cached | ||
76 | version of repository pages accessed with a fixed SHA1. Default value: | ||
77 | "5". | ||
78 | |||
79 | case-sensitive-sort:: | 87 | case-sensitive-sort:: |
80 | Sort items in the repo list case sensitively. Default value: "1". | 88 | Sort items in the repo list case sensitively. Default value: "1". |
81 | See also: repository-sort, section-sort. | 89 | See also: repository-sort, section-sort. |