golang-samber-hot

Configure samber/hot in-memory caches with TTL, eviction, and singleflight.

5|1|Updated Apr 14, 2026
One-click install
npx skills add https://github.com/omarluq/og-template --skill golang-samber-hot-omarluq
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-samber-hot
Source: https://github.com/omarluq/og-template/tree/main/.agents/skills/golang-samber-hot
Command: npx skills add https://github.com/omarluq/og-template --skill golang-samber-hot-omarluq

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Go services often pay latency and backend load penalties when repeatedly querying data that is hot in production. This Skill provides a robust in-memory cache using samber/hot with TTL, multiple eviction policies, loader chains, sharding, and observability to accelerate common paths.

Core Features & Use Cases

  • Nine eviction algorithms (LRU, LFU, TinyLFU, W-TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, FIFO) with TTL, loaders, and singleflight.
  • Support for stale-while-revalidate, missing-key caching, and optional Prometheus metrics for monitoring.
  • Sharding, copy-on-read/copy-on-write, and optional warm-up or preloading patterns for production readiness.
  • Use case: caching high-traffic API responses, config lookups, or database queries to dramatically reduce backend pressure.

Quick Start

Instantiate a hot cache with a 10_000 capacity, a 5-minute TTL, janitor enabled, and a loader chain to demonstrate miss handling.

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 an in-memory cache in Go with TTL and eviction policies?

You can implement an in-memory cache in Go using samber/hot, which provides TTL-based expiration alongside nine eviction algorithms including LRU, LFU, TinyLFU, and S3FIFO to manage capacity and reduce backend load.

What's the best way to handle cache misses in high-concurrency Go services?

Handle cache misses in high-concurrency Go services by configuring loader chains with singleflight, ensuring only one fetch request populates the cache while concurrent requests wait for the result.

Does the samber/hot cache support Prometheus metrics for monitoring?

Yes, samber/hot supports optional Prometheus metrics, allowing you to monitor cache hit rates, misses, and eviction counts to maintain observable caching behavior in production.

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

Yes, you can use stale-while-revalidate and missing-key caching in Go applications to serve stale data during background refreshes and prevent repeated backend queries for non-existent keys.

How do I configure sharding in a Go cache to improve high-concurrency throughput?

Configure sharding in a Go cache using the samber/hot builder API to split data across multiple internal shards, reducing lock contention and improving throughput for high-concurrency access patterns.

What eviction algorithm should I use for mixed access patterns in a Go cache?

For mixed access patterns in a Go cache, W-TinyLFU or ARC eviction algorithms often provide better hit rates by adapting to frequency and recency simultaneously compared to standard LRU or FIFO.