Repolode
allegro

allegro/bigcache

Fast, concurrent, evicting in-memory cache for Go that stores large numbers of entries on the heap while keeping GC overhead low.

Stars
8,172
Forks
620
Open issues
101
Last commit
12 days ago

What is it?

BigCache is an in-memory cache library for Go, designed to hold a large number of entries without the garbage collector slowing down the program. Entries are kept on the heap in byte slices that the GC does not scan entry by entry, so most use cases serialize values to bytes before storing them.

The cache is sharded for concurrent access and evicts entries after a configurable LifeWindow, with a CleanWindow controlling how often expired entries are removed. Memory can be preallocated from expected load, or allowed to grow, with an optional HardMaxCacheSize cap in MB. Optional callbacks fire when entries are removed due to expiry, space limits, or explicit deletion.

The project requires Go 1.12 or newer and includes a separate HTTP server package built on the cache. Hash collisions are not handled: a new item with the same hash overwrites the existing one.

Key features

  • 01Stores entries as byte slices on the heap to reduce GC pause time.
  • 02Sharded design for concurrent reads and writes.
  • 03Time-based eviction through LifeWindow and CleanWindow.
  • 04Optional hard memory cap via HardMaxCacheSize.
  • 05Removal callbacks for expiry, overflow, and deletion.
  • 06Includes an HTTP server package built on the cache.

Use cases

  • Caching gigabytes of serialized data in a long-running Go service.
  • Reducing GC overhead in services that hold millions of cache entries.
  • Providing a local, in-process cache with time-based expiry.

Quick start

  1. 1

    Add the BigCache v3 module to your Go project

  2. 2

    Create a cache with the default config (10 minute life window)

  3. 3

    Set and get entries as byte slices

Things to know

  • Entries must be serialized to byte slices, so most use cases need extra (de)serialization code.
  • BigCache does not handle hash collisions; a colliding new item overwrites the existing value.

Topics

FAQ

What is bigcache?
Fast, concurrent, evicting in-memory cache for Go that stores large numbers of entries on the heap while keeping GC overhead low. BigCache is an in-memory cache library for Go, designed to hold a large number of entries without the garbage collector slowing down the program. Entries are kept on the heap in byte slices that the GC does not scan entry by entry, so most use cases serialize values to bytes before storing them.
Is bigcache free to use? What license does it have?
bigcache is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is bigcache still maintained?
Actively maintained. The last commit to bigcache was on Oct 12, 2026.
What can I use bigcache for?
Caching gigabytes of serialized data in a long-running Go service. Reducing GC overhead in services that hold millions of cache entries. Providing a local, in-process cache with time-based expiry.
How do I install bigcache?
Add the BigCache v3 module to your Go project Create a cache with the default config (10 minute life window) Set and get entries as byte slices
Where can I get bigcache?
The source code and installation instructions are on GitHub: https://github.com/allegro/bigcache

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects