golang-samber-hot

Implements in-memory caching in Go using samber/hot with eviction algorithms, TTL, loaders, and Prometheus metrics.

1|Updated Feb 2, 2026
One-click install
npx skills add https://github.com/rockcookies/skills --skill golang-samber-hot-rockcookies
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-samber-hot
Source: https://github.com/rockcookies/skills/tree/main/skills/samber-golang/golang-samber-hot
Command: npx skills add https://github.com/rockcookies/skills --skill golang-samber-hot-rockcookies

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/samber/hot, and includes references (resource) components.

What problem does it solve? Choosing and configuring an in-memory cache in Go involves subtle decisions — eviction algorithm selection, TTL and janitor setup, loader error handling, and capacity sizing — where common mistakes (forgetting WithJanitor, calling SetMissing without a missing cache, combining WithoutLocking with WithJanitor) cause runtime panics or silently stale data. ## Core Features & Use Cases - Eviction Algorithm Selection: Guidance and decision trees for all 9 samber/hot algorithms (LRU, LFU, TinyLFU, W-TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, FIFO) matched to access patterns. - Production Patterns: Loader chains with singleflight deduplication, stale-while-revalidate, sharding for lock contention, missing-key (negative) caching, copy-on-read/write, warm-up, and Prometheus monitoring. - Use Case: A Go service caches user lookups with a read-through loader, 5-minute TTL with jitter, 16 shards to reduce mutex contention, and Prometheus metrics alerting when hit rate drops below 80%. ## Quick Start Set up a samber/hot cache in my Go service with W-TinyLFU, a 5-minute TTL, a database loader, and Prometheus metrics.

Frequently Asked Questions about golang-samber-hot

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

FAQPage Schema
How do I set up an in-memory cache in Go with samber/hot?▼

Call hot.NewHotCache[K, V] with an eviction algorithm and capacity, chain .WithTTL() and .WithJanitor() in the builder, then call .Build(). Always defer cache.StopJanitor() so the background expiration goroutine is cleaned up.

Which samber/hot eviction algorithm should I use?▼

Start with hot.WTinyLFU, the general-purpose default for mixed or unknown access patterns. Use hot.LFU for stable frequency-dominated workloads, hot.LRU for recency-dominated data, and hot.SIEVE for simple scan resistance.

How do I prevent thundering herd on cache miss in samber/hot?▼

Register a loader with .WithLoaders() — samber/hot includes built-in singleflight deduplication, so concurrent Get() calls for the same missing key share one loader invocation. Add .WithJitter() to spread TTL expirations.

Why does samber/hot panic when I call SetMissing?▼

SetMissing panics unless a missing cache is configured first. Add .WithMissingCache(algorithm, capacity) or .WithMissingSharedCache() in the builder chain before calling Build().

Can I use WithoutLocking with WithJanitor in samber/hot?▼

No, WithoutLocking() and WithJanitor() are mutually exclusive and panic at runtime. WithoutLocking() is only safe for single-goroutine access without background cleanup; drop one of the two options.

How do I monitor a samber/hot cache with Prometheus?▼

Chain .WithPrometheusMetrics(cacheName) in the builder and register the cache with prometheus.MustRegister(cache), since HotCache implements prometheus.Collector. Alert when hit rate falls below 80% or eviction rate spikes.