Caching

LaunchFast provides two caches and a management dashboard at /admin/cache for inspecting and clearing cached values.

Two caches

  • SQLite cache — a separate database from the main application, replicated via LiteFS across all instances. Use for long-lived cached values.
  • LRU cache — an in-memory cache, not replicated, cleared on restart. Use for short-lived cached values and request deduplication.

The cachified API

You interact with the caches through @epic-web/cachified, which provides TTL, stale-while-revalidate, and schema validation:

import { cachified, cache } from '#app/utils/cache.server.ts'

const data = await cachified({
  key: 'my-cache-key',
  cache,
  getFreshValue: () => fetchExpensiveData(),
  ttl: 1000 * 60 * 60 * 24,           // 24 hours
  staleWhileRevalidate: 1000 * 60 * 60 * 24 * 30, // 30 days
})

Admin dashboard

The /admin/cache page lets you inspect all cached keys, view their values, and clear individual entries or the entire cache. This is available only to admin users.

When to cache

Caching should not be the first solution to slowness. Optimize queries with database indexes before caching results.

Related