A zero-dependency, generic in-memory cache library for Go with expiration, eviction policies, and sharding.
imcache is a zero-dependency, generic in-memory cache library for the Go programming language. It provides a fast, concurrent-safe way to store and retrieve data in memory with features like expiration, eviction policies, and sharding. It solves the problem of reducing database or API load by caching frequently accessed data directly in the application's memory.
Go developers building applications that require efficient in-memory caching, such as web servers, microservices, or data-intensive processes needing reduced latency and external dependency.
Developers choose imcache for its combination of zero external dependencies, comprehensive feature set (expiration, eviction, sharding), and strong performance demonstrated through benchmarks. Its generic API and concurrency safety make it a robust, drop-in solution for modern Go applications.
A zero-dependency generic in-memory cache Go library
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
imcache has no external dependencies, ensuring easy integration into Go projects without third-party package bloat, as highlighted in its README.
Leverages Go's generics for type-safe caching, allowing compile-time checks and eliminating the need for manual type assertions with interface{}.
Supports absolute, sliding, and date-based expiration, providing fine-grained control over cache entry lifetimes, as detailed in usage examples.
Implements sharding to distribute cache entries, reducing lock contention and improving parallel performance, evidenced by benchmarks in the README.
Offers multiple eviction policies (LRU, LFU, random) and callbacks for eviction events, enabling sophisticated cache management.
Benchmarks show basic Get operations are slower than a vanilla Go map with mutex (e.g., 428.5 ns/op vs 327.8 ns/op), due to feature complexity.
As an in-memory cache, it does not support data persistence or cross-instance synchronization, limiting scalability to single deployments.
The API requires verbose option passing (e.g., WithCleanerOption, WithEvictionCallbackOption), which can be cumbersome for straightforward caching needs.
Features like the background cleaner and eviction callbacks run in separate goroutines, potentially increasing goroutine count and requiring careful resource management.