golang-samber-hot

Configure in-memory Go caches with samber/hot eviction, TTL, and Prometheus metrics.

2.9k|191|Updated Mar 21, 2026
One-click install
npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-hot
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-hot
Source: https://github.com/samber/cc-skills-golang/tree/main/skills/golang-samber-hot
Command: npx skills add https://github.com/samber/cc-skills-golang --skill golang-samber-hot

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go services often suffer from repeated DB or API calls for hot/cold data. This Skill provides a structured in-memory caching approach using samber/hot to balance recency, frequency, and throughput, with built-in loaders, TTL, and metrics.

Core Features & Use Cases

  • 9 eviction algorithms (LRU, LFU, TinyLFU, W-TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, FIFO)
  • TTL support, singleflight-based loaders, and loader chaining
  • Sharding to reduce lock contention and promote concurrency
  • Stale-while-revalidate, missing-key caching, and Prometheus metrics
  • Production-ready builder patterns with warm-up and Prometheus integration

Quick Start

Set up a Go cache with hot.WTinyLFU, 10_000 capacity, TTL of 5 minutes, janitor, and a basic Get/Set flow.

Frequently Asked Questions about golang-samber-hot

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I implement in-memory caching in Go with configurable eviction strategies?

Implement Go in-memory caching using samber/hot by initializing a cache with NewHotCache, selecting from 9 eviction algorithms like W-TinyLFU or LRU, and configuring capacity, TTL, and sharding via builder chain methods. This supports high-throughput services requiring balanced recency and frequency.

What is the best way to prevent cache stampede in Go services using singleflight loaders?

Prevent cache stampede in Go by configuring singleflight-based loaders within your caching layer. samber/hot consolidates concurrent cache misses for the same key into a single underlying data fetch, reducing redundant DB or API calls while supporting loader chaining for complex workflows.

Does Go in-memory caching with samber/hot support Prometheus metrics and monitoring?

Yes, Go in-memory caching with samber/hot supports Prometheus metrics integration. You can attach a Prometheus metrics collector through the builder pattern, enabling monitoring of cache hits, misses, and evictions to track cache efficiency in production environments.

Can I use stale-while-revalidate and missing-key caching for Go applications?

Yes, you can use stale-while-revalidate and missing-key caching for Go applications. samber/hot allows serving stale data while background loaders fetch fresh values, and it supports caching negative results for missing keys to prevent repeated lookup attempts against the data source.

How do I reduce lock contention in a high-concurrency Go cache?

Reduce lock contention in a high-concurrency Go cache by enabling sharding. samber/hot distributes cache entries across multiple internal shards, minimizing mutex contention and promoting parallel access during heavy read and write operations.

When should I choose W-TinyLFU over LRU or LFU eviction for my Go cache?

Choose W-TinyLFU over LRU or LFU eviction for Go caches facing scan-heavy workloads with bursty access patterns. W-TinyLFU balances recency and frequency better, retaining hot data during transient spikes, whereas LRU may evict frequently accessed items during scans.