cgit

commit 61ff10065b579fa38182fcf10cc7e63839acd53c

Author: Jason A. Donenfeld <Jason@zx2c4.com>

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>

 cgit.c | 15 ++++++++++++---
 cgit.h | 1 +
 cgitrc.5.txt | 28 ++++++++++++++++++----------


diff --git a/cgit.c b/cgit.c
index 950b87834e81fdc5bb2210a6964499811b642096..a45ce1ff7de5a88af2dc287c918099a5cd62d53f 100644
--- a/cgit.c
+++ b/cgit.c
@@ -211,6 +211,8 @@ 	else if (!strcmp(name, "cache-static-ttl"))
 		ctx.cfg.cache_static_ttl = atoi(value);
 	else if (!strcmp(name, "cache-dynamic-ttl"))
 		ctx.cfg.cache_dynamic_ttl = atoi(value);
+	else if (!strcmp(name, "cache-about-ttl"))
+		ctx.cfg.cache_about_ttl = atoi(value);
 	else if (!strcmp(name, "case-sensitive-sort"))
 		ctx.cfg.case_sensitive_sort = atoi(value);
 	else if (!strcmp(name, "about-filter"))
@@ -351,12 +353,13 @@ 	memset(ctx, 0, sizeof(*ctx));
 	ctx->cfg.agefile = "info/web/last-modified";
 	ctx->cfg.nocache = 0;
 	ctx->cfg.cache_size = 0;
-	ctx->cfg.cache_dynamic_ttl = 5;
 	ctx->cfg.cache_max_create_time = 5;
+	ctx->cfg.cache_root = CGIT_CACHE_ROOT;
+	ctx->cfg.cache_about_ttl = 15;
 	ctx->cfg.cache_repo_ttl = 5;
-	ctx->cfg.cache_root = CGIT_CACHE_ROOT;
 	ctx->cfg.cache_root_ttl = 5;
 	ctx->cfg.cache_scanrc_ttl = 15;
+	ctx->cfg.cache_dynamic_ttl = 5;
 	ctx->cfg.cache_static_ttl = -1;
 	ctx->cfg.case_sensitive_sort = 1;
 	ctx->cfg.branch_sort = 0;
@@ -922,6 +925,9 @@
 	if (!ctx.qry.page)
 		return ctx.cfg.cache_repo_ttl;
 
+	if (!strcmp(ctx.qry.page, "about"))
+		return ctx.cfg.cache_about_ttl;
+
 	if (ctx.qry.has_symref)
 		return ctx.cfg.cache_dynamic_ttl;
 
@@ -973,7 +979,10 @@ 		cgit_parse_url(ctx.qry.url);
 	}
 
 	ttl = calc_ttl();
-	ctx.page.expires += ttl * 60;
+	if (ttl < 0)
+		ctx.page.expires += 10 * 365 * 24 * 60 * 60; /* 10 years */
+	else
+		ctx.page.expires += ttl * 60;
 	if (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD"))
 		ctx.cfg.nocache = 1;
 	if (ctx.cfg.nocache)




diff --git a/cgit.h b/cgit.h
index f28cf300b5de975f1ef7c460bdefe9743f599361..a474d7777b3b4b5aadb76a9549a49d878c829cdd 100644
--- a/cgit.h
+++ b/cgit.h
@@ -200,6 +200,7 @@ 	int cache_repo_ttl;
 	int cache_root_ttl;
 	int cache_scanrc_ttl;
 	int cache_static_ttl;
+	int cache_about_ttl;
 	int case_sensitive_sort;
 	int embedded;
 	int enable_filter_overrides;




diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index b4603ef2287c204939fd184bd62d56532e963086..9d0c08997298ea6c5e8583c6c874fe7ef004ea69 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -50,31 +50,39 @@ cache-root::
 	Path used to store the cgit cache entries. Default value:
 	"/var/cache/cgit". See also: "MACRO EXPANSION".
 
+cache-static-ttl::
+	Number which specifies the time-to-live, in minutes, for the cached
+	version of repository pages accessed with a fixed SHA1. Negative
+	values have infinite ttl. Default value: -1".
+
 cache-dynamic-ttl::
 	Number which specifies the time-to-live, in minutes, for the cached
-	version of repository pages accessed without a fixed SHA1. Default
-	value: "5".
+	version of repository pages accessed without a fixed SHA1. Negative
+	values have infinite ttl. Default value: "5".
 
 cache-repo-ttl::
 	Number which specifies the time-to-live, in minutes, for the cached
-	version of the repository summary page. Default value: "5".
+	version of the repository summary page. Negative values have infinite
+	ttl. Default value: "5".
 
 cache-root-ttl::
 	Number which specifies the time-to-live, in minutes, for the cached
-	version of the repository index page. Default value: "5".
+	version of the repository index page. Negative values have infinite
+	ttl. Default value: "5".
 
 cache-scanrc-ttl::
 	Number which specifies the time-to-live, in minutes, for the result
-	of scanning a path for git repositories. Default value: "15".
+	of scanning a path for git repositories. Negative values have infinite
+	ttl. Default value: "15".
+
+cache-about-ttl::
+	Number which specifies the time-to-live, in minutes, for the cached
+	version of the repository about page. Negative values have infinite
+	ttl. Default value: "15".
 
 cache-size::
 	The maximum number of entries in the cgit cache. Default value: "0"
 	(i.e. caching is disabled).
-
-cache-static-ttl::
-	Number which specifies the time-to-live, in minutes, for the cached
-	version of repository pages accessed with a fixed SHA1. Default value:
-	"5".
 
 case-sensitive-sort::
 	Sort items in the repo list case sensitively. Default value: "1".