Documentation
¶
Index ¶
- func AddSubnetOpt(m *dns.Msg, ip net.IP)
- type Cache
- func (c *Cache) Load(ctx context.Context, key CacheKey) (msg *dns.Msg, ttl time.Duration)
- func (c *Cache) RefreshTTL(key CacheKey)
- func (c *Cache) Store(ctx context.Context, key CacheKey, mr *dns.Msg, ttl time.Duration)
- func (c *Cache) WithLogger(logger logger.Logger) *Cache
- func (c *Cache) WithMaxSize(n int) *Cache
- type CacheKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores DNS responses with TTL-based expiration and optional size bounding. A zero maxSize means unbounded (backward compatible).
Load returns:
- (nil, 0) on cache miss
- (msg, ttl > 0) on fresh cache hit
- (msg, ttl <= 0) on expired cache hit (for stale-while-revalidate)
func (*Cache) Load ¶
Load returns a cached DNS message and its remaining TTL. The returned message is a deep copy safe for caller mutation.
func (*Cache) RefreshTTL ¶
RefreshTTL resets the timestamp on a cached entry, extending its TTL.
func (*Cache) Store ¶
Store adds a DNS response to the cache. Negative ttl means "do not cache" and is silently skipped. Zero ttl uses the minimum TTL from the answer records (or defaultTTL if none have a positive TTL). Positive ttl overrides all answer TTLs.
func (*Cache) WithLogger ¶
WithLogger sets the logger for cache debug messages.
func (*Cache) WithMaxSize ¶ added in v0.28.1
WithMaxSize sets the maximum number of entries. 0 means unlimited. When the limit is reached, expired entries are evicted first, then the oldest.