resolver

package
v0.28.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSubnetOpt

func AddSubnetOpt(m *dns.Msg, ip net.IP)

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 NewCache

func NewCache() *Cache

NewCache creates an unbounded DNS cache.

func (*Cache) Load

func (c *Cache) Load(ctx context.Context, key CacheKey) (msg *dns.Msg, ttl time.Duration)

Load returns a cached DNS message and its remaining TTL. The returned message is a deep copy safe for caller mutation.

func (*Cache) RefreshTTL

func (c *Cache) RefreshTTL(key CacheKey)

RefreshTTL resets the timestamp on a cached entry, extending its TTL.

func (*Cache) Store

func (c *Cache) Store(ctx context.Context, key CacheKey, mr *dns.Msg, ttl time.Duration)

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

func (c *Cache) WithLogger(logger logger.Logger) *Cache

WithLogger sets the logger for cache debug messages.

func (*Cache) WithMaxSize added in v0.28.1

func (c *Cache) WithMaxSize(n int) *Cache

WithMaxSize sets the maximum number of entries. 0 means unlimited. When the limit is reached, expired entries are evicted first, then the oldest.

type CacheKey

type CacheKey string

CacheKey identifies a cached DNS response by question name, class, and type.

func NewCacheKey

func NewCacheKey(q *dns.Question) CacheKey

NewCacheKey generates a resolver cache key from a DNS question. Returns an empty key if q is nil.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL