-
Book Overview & Buying
-
Table Of Contents
Systems Programming with Zig
By :
Zcache is a high-performance in-memory cache server written in Zig, designed around three cleanly separated layers. At its core sits the storage engine, which implements an LRU cache by combining a hash map and a doubly linked list — the hash map provides O(1) key lookup while the linked list maintains access order, keeping every get, set, and eviction O(1) regardless of cache size. Time-to-live (TTL) expiry is handled lazily: rather than running a background sweep thread, entries are checked and evicted on the first access after their lifetime elapses, keeping the hot path simple and latency predictable. On top of the storage engine sits ZEMP (Zcache Exchange Message Protocol), a custom binary wire protocol where every message begins with a fixed 8-byte prefix containing a magic byte, version, command type, and payload length. That fixed-width prefix is the key design decision: the parser always knows exactly how many bytes to read next without scanning for...