Skip to content

KV and cache

KV and cache serve hot reads at the edge with explicit expiry, and every value rebuilds from the database.

KV and cache serve hot reads at the edge with explicit expiry. Every value is a copy rebuilt from db.sb, so a miss or a loss never loses data.

Contract

  • A cache entry is never a source of truth. db.sb holds the record, and the cache holds a copy with a required expiry.
  • Every entry belongs to one namespace. A Tenant's entries stay in its partition.
  • Expiry defaults to one hour, and a value holds at most 1 MB.
  • Writing to the cache never writes the record. To change a record, call its Verb.
  • An entry tagged with a Thing's $id expires the moment that Thing changes.
  • Losing the whole cache costs latency, never records.
  • No other key-value store holds a Startup's records. Every durable value is a Thing in db.sb.

Verbs

None.

Interfaces

Example

TypeScript
import { $ } from 'startup-builder'

// A price-comparison site caches its laptop category page for ten minutes.
let page = await $.cache.get<string>('category:laptops')
if (!page) {
  const laptops = await $.Collection.query({ query: 'collection_laptops.products' })
  page = JSON.stringify(laptops.rows)
  await $.cache.set('category:laptops', page, { ttl: '10m', tags: ['category_laptops'] })
}