How Pogocache manages data and memory
mainPogocache uses a sharded hashmap architecture designed for low latency and high CPU efficiency.
Sharding and Hashing
- Shards: Data is stored in a sharded hashmap (defaulting to a high fanout, e.g., 4096 shards). The number of shards is automatically configured at startup but can be changed by the user.
- Hashing: A 64-bit hash (using
th64) is generated for each key. The high 32 bits determine the shard, and the low 32 bits determine the position in the per-shard hashmap. - Hashmap Implementation: Each shard uses an independent hashmap with open addressing and Robin Hood hashing.
- Concurrency: Shards are protected by lightweight spinlocks during operations.
Memory and Eviction
- Entry Storage: Each entry is a single heap allocation containing a header, key (using sixpack compression), and value. Optional fields like expiry, CAS, and flags may also be present.
- Expiration: Entries can have an optional expiry. Expired entries are evicted during periodic background sweeps to ensure no more than 10% of total cache memory is occupied by evicted entries.
- Low Memory Eviction: If the system runs low on memory, the
insertoperation automatically evicts older entries using the 2-random algorithm to free memory immediately.