api/src/lib/cache/freshness.ts

24 lines · 650 bytes

 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  ios: 60,
13  github: 7,
14  discord: 14,
15  reddit: 14,
16  docker: 90,
17} as const
18
19export type CacheRoute = keyof typeof CACHE_DAYS
20
21const DAY_SECONDS = 24 * 60 * 60
22
23// Freshness window in seconds for a route, as passed to storage.fetch()
24export const freshSeconds = (route: CacheRoute): number => CACHE_DAYS[route] * DAY_SECONDS