Skip to content

refactor(web): extract magic cache and cookie TTL constants#1304

Merged
adamshiervani merged 1 commit intojetkvm:devfrom
agh:refactor/web-cache-constants
Mar 17, 2026
Merged

refactor(web): extract magic cache and cookie TTL constants#1304
adamshiervani merged 1 commit intojetkvm:devfrom
agh:refactor/web-cache-constants

Conversation

@agh
Copy link
Contributor

@agh agh commented Mar 16, 2026

Problem

web.go has three hardcoded duration values scattered across
seven call sites: 31536000 (1 year), 300 (5 minutes), and
7*24*60*60 (1 week). The numeric literals obscure intent and
make it easy to introduce inconsistencies if one site is changed
but not the others.

Fix

Extract into named constants at the top of web.go:

  • cacheImmutableMaxAge (365 days) — used for /static/assets/immutable/ and /robots.txt
  • cacheShortMaxAge (5 minutes) — used for other cacheable static files
  • authTokenMaxAge (1 week) — used across the four SetCookie call sites for login, password create, password update, and setup

No behavioural change. The Cache-Control headers are now built
with fmt.Sprintf referencing the constants instead of inlining
the raw numbers.

web.go had three hardcoded duration values scattered across
seven call sites:

- 31536000 (1 year) for immutable asset and robots.txt
  Cache-Control headers, appearing on lines 123 and 140
- 300 (5 minutes) for cacheable static file headers, line 131
- 7*24*60*60 (1 week) for authToken cookie MaxAge, appearing
  on lines 535, 706, 760, and 893

Extract these into named constants (cacheImmutableMaxAge,
cacheShortMaxAge, authTokenMaxAge) at the top of the file.
No behavioural change. The constants make the intent readable
at each call site and give maintainers a single place to
adjust these values.

Signed-off-by: Alex Howells <alex@howells.me>
@adamshiervani adamshiervani merged commit 7e8f881 into jetkvm:dev Mar 17, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants