Design a Thread-Safe In-Memory Cache (Deep Dive)

Problem

Apple's deep-dive round often goes below the language. Design a thread-safe, size-bounded in-memory cache and defend every decision around memory and concurrency.

Requirements

  • get(key) / put(key, value, ttl)
  • Bounded by entry count and/or total bytes
  • TTL expiry
  • Safe under concurrent readers and writers

What evaluators look for

  • Lock granularity (single mutex vs sharded/striped locks vs read-write lock)
  • Memory model: how you avoid retain cycles / leaks (ARC, weak refs)
  • Eviction policy interaction with concurrency
  • How you would expose metrics (hit rate, evictions)

Extension

Extend to a multi-process cache shared via mmap — what breaks?

added …
LeaderboardSalaryAccount