api/src/lib/warm/index.ts

18 lines · 547 bytes

2 symbols in this file
 1/**
 2 * Hit this endpoint to repopulate hot data, called as cron,
 3 * so requests after cache expiry don't pay the cold-path cost
 4 * TODO: Not working, lol. Either fix, or remove.
 5 */
 6
 7import type { Storage } from '@/lib/cache'
 8import { log } from '@/lib/log'
 9
10const TOUCH = ['stats', 'services:all', 'categories:all']
11
12export const warmCache = async (storage: Storage) => {
13  for (const key of TOUCH) {
14    const cached = await storage.get(key)
15    if (!cached) log.info('warm_miss', { key })
16  }
17  log.info('warm_done', { count: TOUCH.length })
18}