From 3a41ff8d0cbfd0a7891697acf162f0b5800550ce Mon Sep 17 00:00:00 2001 From: Bryce Kwon Date: Sat, 31 Oct 2026 18:26:03 -1000 Subject: Keep a scan with a negative ttl for good "The cache" promises that a negative ttl never expires, but no age was ever below a negative cache-scan-ttl, so every request started a background rescan. --- MANUAL.txt | 6 ++++-- source/cgit.c | 3 ++- tests/t0003-cache.sh | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/MANUAL.txt b/MANUAL.txt index 473a6e5..1205db1 100644 --- a/MANUAL.txt +++ b/MANUAL.txt @@ -69,8 +69,10 @@ cache-root:: cache-scan-ttl:: Number which specifies the time-to-live, in minutes, for the result of - scanning a path for git repositories. Default value: "15". See also: - "The cache". + scanning a path for git repositories. It is read when scan-path runs, + along with "cache-size" and "cache-root", so all three must be defined + prior to scan-path to apply to the scan. Default value: "15". See also: + "scan-path", "The cache". cache-size:: The maximum number of entries in the cgit cache. When set to "0", diff --git a/source/cgit.c b/source/cgit.c index 254062f..41bbad3 100644 --- a/source/cgit.c +++ b/source/cgit.c @@ -452,8 +452,9 @@ static void process_cached_repolist(const char *path) config_file_parse(cached_rc.buf, apply_config); + // A negative ttl never expires, the same as for a cached page. age = time(NULL) - st.st_mtime; - if (age <= (ctx.cfg.cache_scan_ttl * 60)) + if (ctx.cfg.cache_scan_ttl < 0 || age <= (ctx.cfg.cache_scan_ttl * 60)) goto out; // The list just parsed is stale but usable, so a child rebuilds it diff --git a/tests/t0003-cache.sh b/tests/t0003-cache.sh index e63efa0..fa72015 100755 --- a/tests/t0003-cache.sh +++ b/tests/t0003-cache.sh @@ -434,4 +434,25 @@ test_expect_success 'a config that scans differently keeps its own list' ' ! grep ">two" strict.out ' +# A negative ttl never expires, so a list however old is served and kept. A +# rebuild runs in a child holding the request's copy of fd 9, so cat reaching +# the end of that pipe means any rebuild is done, as the positive ttl after +# it shows. +test_expect_success 'a negative cache-scan-ttl never expires the list' ' + { + echo "cache-scan-ttl=-1" && + cat scanrc + } >foreverrc && + { + echo "repo.url=kept" && + echo "repo.path=$PWD/scanned/one/.git" + } >>"cache5/$scanned_rc" && + touch -t 200001010000 "cache5/$scanned_rc" && + cgit_rc foreverrc "url=" 9>&1 >forever.out | cat && + grep ">kept" forever.out && + grep "^repo.url=kept$" "cache5/$scanned_rc" && + cgit_rc scanrc "url=" 9>&1 >/dev/null | cat && + ! grep "^repo.url=kept$" "cache5/$scanned_rc" +' + test_done -- cgit 2.12.1