Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

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

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. go-freelru

go-freelru

Apache-2.0Gov0.16.0

A GC-less, fast, generic LRU hashmap library for Go with optional locking, sharding, eviction, and expiration.

GitHubGitHub
269 stars25 forks0 contributors

What is go-freelru?

FreeLRU is a Go library that implements a high-performance, GC-less LRU (Least Recently Used) hashmap for caching. It solves the problem of garbage collection overhead in long-running applications with large caches by using a contiguous memory layout and Go generics for type safety. The library provides single-threaded and thread-safe variants optimized for different concurrency levels.

Target Audience

Go developers building performance-sensitive applications that require efficient in-memory caching, such as web servers, data processing pipelines, or real-time systems where low latency and minimal GC pauses are critical.

Value Proposition

Developers choose FreeLRU for its exceptional speed, zero-allocation design for non-pointer types, and flexibility in concurrency models. It outperforms many popular Go caching libraries in benchmarks while offering a simple API and configurable memory overcommitment to tune performance.

Overview

FreeLRU is a high-performance LRU (Least Recently Used) caching library for Go designed to eliminate garbage collection overhead and provide type safety through generics. It offers multiple implementations tailored for different concurrency needs, from single-threaded to high-concurrency environments.

Key Features

  • GC-less Design — Uses a contiguous array to avoid millions of small heap allocations, reducing garbage collection pauses.
  • Generic Type Safety — Leverages Go generics for compile-time type checking and zero runtime allocations for non-pointer types.
  • Multiple Concurrency Models — Provides LRU (single-threaded), SyncedLRU (low-concurrency), and ShardedLRU (high-concurrency) implementations.
  • High Performance — Benchmarks show it outperforms other LRU libraries and even Go maps in many scenarios.
  • Configurable Memory Overcommitment — Allows allocating more hashtable memory to reduce collisions and improve speed.
  • Exact and Approximate LRU — LRU and SyncedLRU use exact LRU algorithms; ShardedLRU uses an approximate algorithm for scalability.

Philosophy

FreeLRU prioritizes performance and low GC overhead by merging hashmap and ringbuffer into a contiguous array, ensuring memory locality and minimizing cache misses. It emphasizes simplicity in API design to ease migration from other LRU implementations.

Use Cases

Best For

  • Reducing garbage collection overhead in long-running Go services
  • High-concurrency applications needing scalable LRU caching
  • Caching primitive types (int, string) without heap allocations
  • Migrating from other LRU libraries with minimal API changes
  • Performance-critical systems where cache speed impacts latency
  • Implementing custom caches with exact or approximate LRU eviction

Not Ideal For

  • Applications requiring automatic time-based expiration (TTL) for cache entries
  • Projects that need eviction callbacks or hooks for cache management
  • Environments where providing custom hash functions adds unnecessary complexity
  • High-concurrency scenarios relying solely on SyncedLRU without sharding

Pros & Cons

Pros

GC-Free Performance

Uses a contiguous array to eliminate heap allocations, achieving zero allocations per operation in benchmarks and reducing GC pauses for long-running applications.

Type-Safe Generics

Leverages Go generics for compile-time type checking and zero runtime allocations for non-pointer types, ensuring both safety and efficiency as highlighted in the README.

Scalable Concurrency Models

Offers SyncedLRU for low concurrency and ShardedLRU for high concurrency, with benchmarks showing ShardedLRU outperforming competitors like Ristretto in parallel tests.

Configurable Memory Overcommitment

Allows allocating extra hashtable memory to reduce collisions, improving speed by up to 20% in performance tests, as demonstrated in the benchmarks section.

Cons

Manual Hash Function Requirement

Callers must provide their own hash function for keys, adding setup overhead and potential for performance issues if suboptimal hashes are chosen, as admitted in the README.

Limited Eviction Features

Supports only LRU eviction without built-in TTL or other policies, missing common caching features that might be needed for applications with complex expiration logic.

Lock Contention in SyncedLRU

The SyncedLRU implementation suffers from significant lock contention in high-concurrency environments, as benchmarks show it performs poorly compared to sharded alternatives.

Frequently Asked Questions

Quick Stats

Stars269
Forks25
Contributors0
Open Issues16
Last commit4 days ago
CreatedSince 2022

Tags

#lru-cache#library#caching#memory-management#data-structures#lru#low-latency#golang#hashmap#cache#concurrency#go#generic-programming#performance

Built With

G
Go

Included in

Go169.1k
Auto-fetched 18 hours ago

Related Projects

groupcachegroupcache

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

Stars13,340
Forks1,392
Last commit1 year ago
BigCacheBigCache

Efficient cache for gigabytes of data written in Go.

Stars8,149
Forks611
Last commit4 days ago
ristrettoristretto

A high performance memory-bound Go cache

Stars6,969
Forks444
Last commit9 days ago
gocachegocache

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

Stars2,877
Forks223
Last commit21 days 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