Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 18, 2026·3 min de lectura

Groupcache — Distributed Caching Library for Go by Google

A distributed caching and cache-filling library for Go, designed as a replacement for memcached in many use cases, with automatic peer-to-peer replication.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Groupcache Overview
Comando de instalación directa
npx -y tokrepo@latest install 65c960d8-8242-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Groupcache is a distributed caching library created by Brad Fitzpatrick at Google. It was built as a memcached replacement for certain workloads at dl.google.com, providing automatic replication across peers and a cache-filling mechanism that prevents thundering herd problems.

What Groupcache Does

  • Distributes cached data across a set of peer processes using consistent hashing
  • Fills cache automatically on miss by calling a user-defined getter function
  • Deduplicates concurrent requests for the same key, preventing thundering herds
  • Replicates hot keys across peers to reduce cross-peer traffic
  • Serves as an in-process library with no external daemon to manage

Architecture Overview

Each groupcache instance runs inside your application process. Peers discover each other via an HTTP-based protocol. When a Get request arrives, groupcache checks the local cache first, then uses consistent hashing to determine which peer owns the key. If the key belongs to a remote peer, it fetches over HTTP. The singleflight mechanism ensures only one goroutine fetches a given key at a time, even under concurrent load.

Self-Hosting & Configuration

  • Add to your project with go get github.com/golang/groupcache
  • Create an HTTPPool with the current node address and set peer URLs
  • Define named groups with a max cache size and a GetterFunc for origin fetches
  • Peers communicate over HTTP — deploy behind a load balancer or service mesh
  • Cache eviction uses LRU; set the byte limit per group to control memory usage

Key Features

  • Singleflight deduplication prevents duplicate work on concurrent cache misses
  • Hot cache automatically replicates frequently accessed keys to reduce peer hops
  • No separate server process — runs embedded in your Go application
  • Consistent hashing distributes keys evenly and handles peer changes gracefully
  • Immutable cache design — values are set once and never updated, simplifying consistency

Comparison with Similar Tools

  • Memcached — external daemon with manual invalidation; groupcache is embedded with automatic fill
  • BigCache — single-node concurrent map; groupcache adds distributed coordination
  • Ristretto — admission-based local cache; groupcache focuses on distributed peer replication
  • Redis — full-featured data store; groupcache is a lighter embedded caching layer

FAQ

Q: Can I update or delete cached values? A: Groupcache treats values as immutable. For mutable data, use a versioned key scheme or a different solution.

Q: How do peers discover each other? A: You provide the list of peer URLs via pool.Set(). Integrate with your service discovery system to keep this list current.

Q: Is groupcache still maintained? A: The library is stable and used in production at Google. It receives maintenance updates but the API is considered complete.

Q: How large can the cache be? A: Each group has a configurable byte limit. The total memory used is the sum of all group limits on each process.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados