🍡 mochi
SSR framework for Svelte 5 + Bun with islands-based selective hydration
On this page
Persistence
A few Mochi features keep server-side state that outlives a single request — queued jobs, cached values, rate-limit counters, spent captcha nonces. Each one defaults to in-memory storage and can be pointed at something durable instead.
| Feature | Memory | SQLite | Postgres | File |
|---|---|---|---|---|
| Queues | supported , default | supported | supported | not supported |
| Cache | supported , default | planned | planned | supported |
| Image cache | supported | not supported | not supported | supported , default |
| Rate limiting | supported , default | supported | supported | not supported |
| Captcha nonces | supported , default | supported | not supported | not supported |
default backend planned, not available yet
Built-in backends only — most features also accept a store you write yourself. In-memory state is per process, so it gives no shared view across a multi-instance deploy.
Per feature
- Queues — in-memory by default. Point the serve-level
queueStorage(or a descriptor’sstorage) at a SQLite file ({ sqlite: path }), a Postgres database ({ postgres: url }), or an embedded PGlite instance ({ pglite }). One store serves every queue; Postgres storage is shared, so multiple processes can work one backlog. - Cache —
new MochiCache({ storage }). Defaults toMemoryStorage;FileStoragewrites one JSON file per entry. Built-in SQLite and Postgres backends are planned; until then any other backend is aStorageimplementation (getItem/setItem/removeItem/clear), withserialize/deserializewhen the backend needs strings. - Image cache — the one feature that persists by default:
FileStorageundercacheDir. Passimage: { storage }to swap it (e.g.new MemoryStorage());cacheDiris then ignored. - Rate limiting —
rateLimit: { store }.memoryStore()(default),sqliteStore({ path })andpostgresStore({ url })all ship with the framework;MochiRateLimitStoreis the interface for your own. Create the store once and share the instance across routes. - Captcha —
captcha: { store: 'memory' | 'sqlite' }, plusstorePathfor the SQLite file. A customNonceStoreneeds onlyconsume(nonce, expiresAt).
Choosing a backend
| Backend | Survives restart | Shared across instances | Use it when |
|---|---|---|---|
| In-memory | No | No | Development, single-process apps, state that’s cheap to rebuild |
| File | Yes | Only on shared storage | Caches whose entries are large blobs (images, API responses) |
| SQLite | Yes | Only on shared storage | One host, one process — durability without another service |
| Postgres | Yes | Yes | Several instances behind a load balancer |