gitmyhub

go-cache

Go ★ 8.8k updated 2y ago

An in-memory key:value store/cache (similar to Memcached) library for Go, suitable for single-machine applications.

go-cache is a Go library for storing key-value data in memory with optional expiration times, giving you fast in-process caching without needing a separate Redis or Memcached server.

Gosetup: easycomplexity 2/5

go-cache is a Go library that lets a program store data in memory for fast retrieval, without needing a separate caching service running on another machine. You give each item a key, store any value you want alongside it, and optionally set a time after which that item expires and gets cleaned up automatically. If no expiration is set, the item stays until your program removes it or shuts down.

The library is designed to be safe when multiple parts of a program read and write to the cache at the same time. It works purely in the same process memory, so there is no network involved and no serialization overhead. This makes reads and writes very fast, but also means the cache only lives for as long as the program is running on that one machine.

There is a way to save the cache contents to a file and reload them when the program restarts, which can help recover quickly after a restart. The documentation notes some caveats around that feature.

This is a library for Go developers, not a standalone tool. You add it to a Go project with a single install command and then import it in your code. The README includes clear usage examples showing how to store and retrieve values. The project is compact and focused: it does in-memory caching for single-machine Go applications and nothing else.

Where it fits