api/src/lib/cache/freshness.ts

26 lines · 747 bytes

4 symbols in this file
 1/**
 2 * Central cache freshness windows, in days, per enrichment route.
 3 * A cached response is served as-is until it is this many days old, then a
 4 * refresh is attempted. To change how long a route caches, edit one number here.
 5 */
 6
 7export const CACHE_DAYS = {
 8  privacy: 90,
 9  security: 14,
10  android: 60,
11  website: 60,
12  trackers: 30,
13  trackerBlocklist: 7, // Shared DuckDuckGo blocklist used by the trackers route
14  ios: 60,
15  github: 7,
16  discord: 14,
17  reddit: 14,
18  docker: 90,
19} as const
20
21export type CacheRoute = keyof typeof CACHE_DAYS
22
23const DAY_SECONDS = 24 * 60 * 60
24
25// Freshness window in seconds for a route, as passed to storage.fetch()
26export const freshSeconds = (route: CacheRoute): number => CACHE_DAYS[route] * DAY_SECONDS