Documentation
¶
Overview ¶
Package dedup provides a bounded, TTL-based idempotency cache for deduplicating repeated requests by request ID.
Index ¶
Constants ¶
const DefaultMaxEntries = 10_000
DefaultMaxEntries caps the request_id→result cache.
const DefaultMaxResult = 64 * 1024
DefaultMaxResult skips caching replies larger than this.
const DefaultTTL = 5 * time.Minute
DefaultTTL is the default time-to-live for cache entries.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache deduplicates repeated command requests by caching request_id → result for a bounded TTL. It owns its own mutex so check/record operations don't contend with other subsystems.
func (*Cache) Record ¶
Record stores a request_id → result mapping. Enforces two bounds: results over maxResult are not cached, and when the map hits maxEntries the oldest entry is evicted via a min-heap in O(log n). Falls back to an O(n) scan if the heap is empty.
func (*Cache) StartCleaner ¶
func (c *Cache) StartCleaner(done <-chan struct{})
StartCleaner runs a periodic sweep that removes expired entries. Exits when done is closed.