An in-memory key-value store/cache library for Go, similar to Memcached, designed for single-machine applications.
go-cache is an in-memory key-value store and cache library for Go, similar to Memcached but designed for single-machine applications. It provides a thread-safe map with expiration times, allowing developers to cache any Go object without the overhead of network serialization. The library helps improve application performance by storing frequently accessed data in memory with automatic cleanup of expired items.
Go developers building single-machine applications that require efficient in-memory caching, such as web servers, APIs, or background job processors that need fast data access without external dependencies.
Developers choose go-cache for its simplicity, zero network overhead, and native Go integration—it's essentially a thread-safe map with expiration times. Unlike distributed caches like Memcached, it's optimized for single-machine use cases where network latency isn't needed, making it faster and easier to deploy.
An in-memory key:value store/cache (similar to Memcached) library for Go, suitable for single-machine applications.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Provides a concurrent-safe map that can be used by multiple goroutines without data races, as explicitly stated in the README's description of being 'thread-safe'.
Supports setting expiration durations for cached items or storing them indefinitely with no expiration, allowing precise control over cache lifecycle as demonstrated in the usage examples.
Allows saving the entire cache to a file and loading it back using c.Items() and NewFrom(), enabling quick recovery from downtime, though the README notes caveats for this feature.
Can store pointers to Go objects to optimize performance by avoiding copying, as recommended in the README with examples like storing &MyStruct for efficiency.
Designed only for applications running on a single machine, making it unsuitable for distributed systems that require cache sharing across nodes, as emphasized in the project's philosophy.
Stores values as interface{}, requiring developers to perform type assertions when retrieving data, which can lead to runtime errors if not handled carefully, as illustrated in the README's tedious examples.
Only supports time-based expiration and lacks advanced eviction algorithms like LRU, which might be necessary for optimizing cache hit rates in memory-constrained scenarios.
The README mentions caveats when using NewFrom() to load cache from files, indicating that persistence is not fully robust and may require additional error handling or serialization efforts.
go-cache is an open-source alternative to the following products: