FreeCache is a cache library for Go that eliminates garbage collection overhead while maintaining high concurrent performance.
The problem FreeCache solves is the expensive GC latency introduced by long-lived objects in memory. Traditional in-memory caches force developers to choose between storing many objects and accepting GC pauses, or limiting cache size to keep GC manageable. FreeCache achieves zero GC overhead by drastically reducing the number of pointers in the system. Rather than creating individual pointer allocations for each cached entry, the library uses a fixed architecture: the entire dataset is sharded into 256 segments by key hash, with each segment containing only two pointers—one for a ring buffer storing keys and values, and one for an index slice used for lookups. This design allows the cache to store hundreds of millions of entries without triggering additional garbage collection, regardless of cache size.
FreeCache suits applications that need to cache large numbers of objects in memory while maintaining predictable latency. It works well for systems where GC pauses are unacceptable, such as low-latency services or high-throughput data processing. The library includes expiration support with nearly-LRU eviction semantics, strictly enforces memory limits through preallocation, and provides thread-safe concurrent access through per-segment locking. It comes with a toy Redis-compatible server supporting basic commands with pipelining, and offers iterator support for scanning cached entries. Benchmark results show Set operations are roughly twice as fast as Go's built-in map, though Get operations are somewhat slower in single-threaded scenarios; however, the library is designed to outperform a single-lock-protected map significantly in multi-threaded environments.
Development activity shows consistent maintenance with attention to practical deployment concerns. The project documents important operational details including memory preallocation requirements and the interaction between GC tuning and cache sizing. The expiration semantics are precisely specified, noting that effective cache duration falls within a one-second window due to sub-second time truncation during expiration calculation. The roadmap indicates planned features for persistence and runtime resizing, suggesting ongoing evolution to meet user needs.