Documentation
¶
Overview ¶
Package cache provides a capacity-bounded TTL cache with Prometheus metrics and singleflight de-duplication. Consumers compose their own value semantics (negative caching, optional wrapping, etc.) on top of the primitive.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache[K comparable, V any] struct { TTL *ttlcache.Cache[K, V] SF singleflight.Group // contains filtered or unexported fields }
Cache is a capacity-bounded TTL cache with a Prometheus size gauge and a singleflight group for de-duplicating concurrent loads.
TTL and SF are exposed so consumers can use the underlying ttlcache and singleflight APIs directly without thin re-wrapping.
func New ¶
func New[K comparable, V any](options Options) *Cache[K, V]
New constructs a Cache with WithDisableTouchOnHit (pure TTL, no LRU touch).
func (*Cache[K, V]) Collect ¶
func (c *Cache[K, V]) Collect(ch chan<- prometheus.Metric)
Collect implements prom.Collector.
func (*Cache[K, V]) Describe ¶
func (c *Cache[K, V]) Describe(ch chan<- *prometheus.Desc)
Describe implements prom.Collector.
type Options ¶
type Options struct {
// MetricsNamespace is prepended to MetricsName in the exported gauge.
MetricsNamespace string
// MetricsName is the Prometheus gauge name for the cache size.
MetricsName string
// MetricsHelp is the Prometheus gauge help string.
MetricsHelp string
// Capacity caps the number of entries; LRU eviction kicks in at the limit.
Capacity uint64
}
Options configures a Cache.