From: tim.nordell at logicpd.com (Tim Nordell)
Subject: [PATCH 1/2] ttl: Consolidate TTL calculation
Date: Fri, 26 Feb 2016 14:57:08 -0600 [thread overview]
Message-ID: <1456520229-11888-2-git-send-email-tim.nordell@logicpd.com> (raw)
In-Reply-To: <1456520229-11888-1-git-send-email-tim.nordell@logicpd.com>
Currently part of the TTL calculation is done outside of the
calc_ttl() function. Ideally a single variable in main()
would have the total seconds until the cache expires, and
ctx.page.expires would be incremented by this, as well
as the parameter to cache_process getting this value in
seconds.
Signed-off-by: Tim Nordell <tim.nordell at logicpd.com>
diff --git a/cache.c b/cache.c
index 6736a01..417f1a2 100644
--- a/cache.c
+++ b/cache.c
@@ -126,7 +126,7 @@ static int is_expired(struct cache_slot *slot)
if (slot->ttl < 0)
return 0;
else
- return slot->cache_st.st_mtime + slot->ttl * 60 < time(NULL);
+ return slot->cache_st.st_mtime + slot->ttl < time(NULL);
}
/* Check if the slot has been modified since we opened it.
diff --git a/cgit.c b/cgit.c
index fc482be..963aee8 100644
--- a/cgit.c
+++ b/cgit.c
@@ -1005,25 +1005,28 @@ static void cgit_parse_args(int argc, const char **argv)
static int calc_ttl(void)
{
- if (!ctx.repo)
- return ctx.cfg.cache_root_ttl;
-
- if (!ctx.qry.page)
- return ctx.cfg.cache_repo_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;
+ const int ttl_conversion_multiplier = 60;
+ int ttl;
- if (ctx.qry.has_sha1)
- return ctx.cfg.cache_static_ttl;
+ if (!ctx.repo)
+ ttl = ctx.cfg.cache_root_ttl;
+ else if (!ctx.qry.page)
+ ttl = ctx.cfg.cache_repo_ttl;
+ else if (!strcmp(ctx.qry.page, "about"))
+ ttl = ctx.cfg.cache_about_ttl;
+ else if (!strcmp(ctx.qry.page, "snapshot"))
+ ttl = ctx.cfg.cache_snapshot_ttl;
+ else if (ctx.qry.has_sha1)
+ ttl = ctx.cfg.cache_static_ttl;
+ else if (ctx.qry.has_symref)
+ ttl = ctx.cfg.cache_dynamic_ttl;
+ else
+ ttl = ctx.cfg.cache_repo_ttl;
- if (ctx.qry.has_symref)
- return ctx.cfg.cache_dynamic_ttl;
+ if (ttl >= 0)
+ return ttl * ttl_conversion_multiplier;
- return ctx.cfg.cache_repo_ttl;
+ return 10 * 365 * 24 * 60 * 60; /* 10 years */
}
int main(int argc, const char **argv)
@@ -1076,10 +1079,7 @@ int main(int argc, const char **argv)
authenticate_cookie();
ttl = calc_ttl();
- if (ttl < 0)
- ctx.page.expires += 10 * 365 * 24 * 60 * 60; /* 10 years */
- else
- ctx.page.expires += ttl * 60;
+ ctx.page.expires += ttl;
if (!ctx.env.authenticated || (ctx.env.request_method && !strcmp(ctx.env.request_method, "HEAD")))
ctx.cfg.nocache = 1;
if (ctx.cfg.nocache)
--
2.4.9
next prev parent reply other threads:[~2016-02-26 20:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-26 20:57 [PATCH 0/2] TTL updates tim.nordell
2016-02-26 20:57 ` tim.nordell [this message]
2016-02-28 12:22 ` [PATCH 1/2] ttl: Consolidate TTL calculation john
2016-02-26 20:57 ` [PATCH 2/2] ttl: Support different TTL times based on cache-control tim.nordell
2016-02-28 12:32 ` john
2016-02-29 15:08 ` tim.nordell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1456520229-11888-2-git-send-email-tim.nordell@logicpd.com \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).