samber-hot

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

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill samber-hot-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: samber-hot
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/samber/samber-hot
Command: npx skills add https://github.com/asarchami/dotfiles --skill samber-hot-asarchami

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 hard decisions: which eviction algorithm fits the access pattern, how to size capacity from a memory budget, and how to avoid stale data, thundering herds, and runtime panics. This Skill guides those decisions for the samber/hot caching library. ## Core Features & Use Cases - Algorithm Selection: Choose among W-TinyLFU, LRU, LFU, TinyLFU, S3FIFO, ARC, TwoQueue, SIEVE, and FIFO based on measured access patterns, with a decision tree and comparison matrix. - Cache Construction: Build caches with TTL, jitter, janitor goroutines, read-through loaders with singleflight deduplication, copy-on-read/write protection, and missing-key (negative) caching. - Capacity Sizing & Monitoring: Derive capacity from a memory budget and measured item size, then track hit rate and eviction rate with Prometheus metrics. - Use Case: A Go service repeatedly loads the same user records from a database. Use this Skill to build a W-TinyLFU cache with a batch loader, TTL with jitter, sharding for concurrency, and Prometheus dashboards to validate hit rate above 80%. ## Quick Start Ask the AI to build a samber/hot cache for your Go service with a TTL, a database loader, and Prometheus metrics, sized for a given memory budget.

Frequently Asked Questions about samber-hot

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

FAQPage Schema
How do I choose an eviction algorithm for samber/hot in Go?

Start with W-TinyLFU as the general-purpose default for mixed workloads. Switch only when measured hit rate misses your SLO: use LRU for recency-dominated patterns, LFU for stable frequency patterns, S3FIFO for large high-throughput caches, and ARC for self-tuning when patterns are unknown.

How do I set up a read-through cache with a loader in samber/hot?

Chain WithLoaders on the builder with a function that batch-fetches missing keys, such as a database query. Concurrent Get calls for the same missing key share one loader invocation via singleflight deduplication, and you should check both err and found on every Get.

How do I size cache capacity from a memory budget?

Estimate per-entry cost as struct size plus heap-allocated fields, key size, and roughly 100 bytes of bookkeeping overhead. Divide your memory budget by that item size and round down; measure item size with a test using runtime.ReadMemStats rather than guessing.

Why does SetMissing panic in samber/hot?

SetMissing panics at runtime if the missing cache was not configured in the builder. Add WithMissingCache(algorithm, capacity) for a dedicated negative cache or WithMissingSharedCache() to store missing keys in the main cache before calling SetMissing.

Can I use WithoutLocking with a janitor in samber/hot?

No, WithoutLocking and WithJanitor are mutually exclusive. Background expiration cleanup requires locking, so keep locking enabled whenever the janitor runs; WithoutLocking is only safe for single-goroutine access.

How do I monitor samber/hot cache hit rate with Prometheus?

Add WithPrometheusMetrics(cacheName) to the builder and register the cache with prometheus.MustRegister, since HotCache implements prometheus.Collector. Track hit ratio with rate(hot_cache_hit_count) / rate(hot_cache_get_count) and treat values below 80% as a sign of undersized capacity or the wrong algorithm.