From a3722ec3c6660ace9fe637d617a0ca225acfacbc Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Wed, 5 Feb 2014 10:23:58 +0100 Subject: Add a cache-snapshot-ttl configuration variable This can be used to specify the TTL for snapshots. Snapshots are usually static and do not ever change. On the other hand, tarball generation is CPU intensive. One use case of this setting (apart from increasing the lifetime of snapshot cache slots) is caching of snapshots while disabling the cache for static/dynamic HTML pages (by setting TTL to zero for everything except for snapshot requests). Signed-off-by: Lukas Fleischer --- cgit.c | 6 ++++++ cgit.h | 1 + cgitrc.5.txt | 5 +++++ 3 files changed, 12 insertions(+) diff --git a/cgit.c b/cgit.c index 36251e7..f488ebf 100644 --- a/cgit.c +++ b/cgit.c @@ -184,6 +184,8 @@ static void config_cb(const char *name, const char *value) 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, "cache-snapshot-ttl")) + ctx.cfg.cache_snapshot_ttl = atoi(value); else if (!strcmp(name, "case-sensitive-sort")) ctx.cfg.case_sensitive_sort = atoi(value); else if (!strcmp(name, "about-filter")) @@ -331,6 +333,7 @@ static void prepare_context(void) ctx.cfg.cache_max_create_time = 5; ctx.cfg.cache_root = CGIT_CACHE_ROOT; ctx.cfg.cache_about_ttl = 15; + ctx.cfg.cache_snapshot_ttl = 5; ctx.cfg.cache_repo_ttl = 5; ctx.cfg.cache_root_ttl = 5; ctx.cfg.cache_scanrc_ttl = 15; @@ -995,6 +998,9 @@ static int calc_ttl() if (!strcmp(ctx.qry.page, "about")) return ctx.cfg.cache_about_ttl; + if (!strcmp(ctx.qry.page, "snapshot")) + return ctx.cfg.cache_snapshot_ttl; + if (ctx.qry.has_sha1) return ctx.cfg.cache_static_ttl; diff --git a/cgit.h b/cgit.h index 496d0f6..0badc64 100644 --- a/cgit.h +++ b/cgit.h @@ -210,6 +210,7 @@ struct cgit_config { int cache_scanrc_ttl; int cache_static_ttl; int cache_about_ttl; + int cache_snapshot_ttl; int case_sensitive_sort; int embedded; int enable_filter_overrides; diff --git a/cgitrc.5.txt b/cgitrc.5.txt index 8eafc4a..a437fc4 100644 --- a/cgitrc.5.txt +++ b/cgitrc.5.txt @@ -88,6 +88,11 @@ cache-about-ttl:: version of the repository about page. Negative values have infinite ttl. Default value: "15". +cache-snapshot-ttl:: + Number which specifies the time-to-live, in minutes, for the cached + version of snapshots. Negative values have infinite ttl. Default + value: "5". + cache-size:: The maximum number of entries in the cgit cache. Default value: "0" (i.e. caching is disabled). -- cgit 1.4.1