Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. cache2go

cache2go

NOASSERTIONGov0.2

A concurrency-safe Go caching library with expiration capabilities and access counters.

GitHubGitHub
2.2k stars504 forks0 contributors

What is cache2go?

cache2go is a concurrency-safe in-memory caching library for Go, designed to store arbitrary data types with configurable expiration times. It solves the problem of efficiently caching frequently accessed data in multi-goroutine environments, reducing latency and backend load.

Target Audience

Go developers building applications that require fast, thread-safe caching, such as web servers, APIs, or data processing pipelines.

Value Proposition

Developers choose cache2go for its simplicity, built-in concurrency safety, and flexible expiration features without external dependencies, making it a lightweight alternative to more complex caching solutions.

Overview

Concurrency-safe Go caching library with expiration capabilities and access counters

Use Cases

Best For

  • Adding in-memory caching to Go web servers to reduce database queries
  • Storing session data or temporary results in concurrent applications
  • Implementing expiring key-value stores for rate limiting or feature flags
  • Caching API responses or computed values with automatic cleanup
  • Learning caching patterns in Go due to its minimal and readable codebase
  • Prototyping applications that need fast, simple caching without setup overhead

Not Ideal For

  • Applications requiring distributed caching across multiple servers, as it's single-process and in-memory
  • Projects needing persistent cache storage to survive application restarts, since data is volatile
  • Systems that demand advanced eviction policies like LRU or LFU, as it relies only on expiration and access counters
  • Teams looking for integrated monitoring dashboards or extensive tooling, due to its minimalistic design

Pros & Cons

Pros

Built-in Concurrency Safety

Uses synchronization to ensure safe access from multiple goroutines without data races, as explicitly stated in the README's key features, making it reliable for concurrent Go applications.

Flexible Expiration Options

Supports item expiration after a fixed duration or never, with automatic cleanup, reducing manual management overhead and highlighted in the example code for easy implementation.

Arbitrary Type Support

Allows storing any Go data type, including structs and slices, as keys and values, enhancing versatility for diverse caching needs, as demonstrated in the provided example with a custom struct.

Customizable Callbacks

Offers hooks like AboutToDeleteItem for executing custom logic before item removal, enabling advanced use cases such as logging or cleanup, as shown in the README example.

Cons

No Persistence Support

As an in-memory cache, all data is lost on application restart, which the README does not address, limiting its use for scenarios requiring durable cache storage.

Limited Eviction Strategies

Relies solely on expiration for cleanup; while it tracks access counts, it lacks built-in policies like LRU or LFU, which might necessitate custom implementations for optimal cache management.

Single-Process Limitation

Designed for use within a single Go process, making it unsuitable for distributed systems or clustered environments where shared cache access is needed, as noted in its minimal architecture.

Frequently Asked Questions

Quick Stats

Stars2,152
Forks504
Contributors0
Open Issues21
Last commit2 years ago
CreatedSince 2013

Tags

#hacktoberfest#in-memory-cache#caching#expiration#data-structures#golang#concurrency#go#cache-library#performance

Built With

G
Go

Included in

Go169.1k
Auto-fetched 8 hours ago

Related Projects

groupcachegroupcache

groupcache is a caching and cache-filling library, intended as a replacement for memcached in many cases.

Stars13,336
Forks1,393
Last commit1 year ago
BigCacheBigCache

Efficient cache for gigabytes of data written in Go.

Stars8,159
Forks612
Last commit7 days ago
ristrettoristretto

A high performance memory-bound Go cache

Stars6,988
Forks443
Last commit5 days ago
gocachegocache

☔️ A complete Go cache library that brings you multiple ways of managing your caches

Stars2,882
Forks223
Last commit1 month ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub