$ show allegro/bigcache
BigCache is a high-performance, concurrent, evicting in-memory cache library for Go, designed to store large numbers of entries without impacting garbage collection. It achieves this by storing entries in byte slices and using a `map[uint64]uint64` (hash to index) that contains no pointers, thus avoiding GC scanning. The cache is sharded for concurrency, supports TTL-based eviction, a configurable cleanup goroutine, and optional hard memory limits. It provides a simple key-value API (Set, Get, Delete, Append) along with iteration, statistics, and per-key metadata. The repository also includes an optional standalone HTTP server that exposes a RESTful API for cache operations, making it suitable for deployment as a caching microservice. The codebase is well-tested with unit tests, benchmarks, and fuzz testing, and follows modern Go practices.
The LLM identified 2 files worth highlighting for reuse:
Implements a non-thread-safe FIFO queue over a byte array with variable-length integer headers (uvarint) for entry sizes. Supports push, pop, peek, and random access by index. Dynamically resizes by doubling capacity when full, handling fragmentation by wrapping the tail to the beginning. This is a self-contained, reusable data structure that can be extracted for any project needing a compact, indexable byte queue with minimal overhead. It demonstrates careful low-level memory management and encoding techniques.
Provides a simple middleware pattern for Go's HTTP handlers, allowing services to be chained. Includes a `requestMetrics` middleware that logs request duration. This pattern is self-contained and can be reused in any Go HTTP server built on the standard library's `http.Handler` interface. It demonstrates a clean functional composition approach for cross-cutting concerns.