Mid-level Track Roadmap

Solid Cache: database internals

This course reads the source of the solid_cache gem and the SQL it sends to Postgres. It follows reads through key_hash and the unique index, and writes through a single upsert that computes byte_size and leaves created_at untouched. It tests unless_exist and increment with ten concurrent threads and explains how the cache size is estimated from two indexes. It shows how expiry deletes rows in id order. It also covers failsafe error handling, Maglev sharding, the background thread, and a comparison with Redis.

What you'll learn

  • ✓How reads hash the key into a signed 64-bit key_hash served by a unique index
  • ✓How a write becomes one upsert, with compression and a computed byte_size
  • ✓Where FOR UPDATE leaves unless_exist and increment non-atomic on missing keys
  • ✓How the cache size is estimated from the byte_size and composite indexes
  • ✓How write-driven expiry deletes the oldest rows by id
  • ✓How failsafe, Maglev sharding and the background thread behave
Free preview · Lesson 1 6 min read

One query per read: key_hash and the unique index

The junior course "Solid Cache: database caching" ended at the table: SolidCache::Entry, one row per cached fragment, with a real byte_size column you could sum. This course opens the gem and reads the code that puts those rows there. Every claim below was run against this application's development…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...