cache

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package cache provides small cache key and strategy helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildKey

func BuildKey(parts KeyParts) (string, error)

BuildKey returns a stable cache key string for the given parts.

Types

type Decision

type Decision int

Decision indicates which global cache bucket should store a result.

const (
	// DecisionNone skips global caching for the query result.
	DecisionNone Decision = iota
	// DecisionPositive stores the result in the positive cache.
	DecisionPositive
	// DecisionNegative stores the result in the negative cache.
	DecisionNegative
)

func Decide

func Decide(result Result) Decision

Decide applies the global caching strategy for DNS query outcomes. Positive responses are cached in the positive cache, while network failures (timeouts, unreachable hosts) are cached in the negative cache.

type ErrorKind

type ErrorKind int

ErrorKind classifies query failures for caching decisions.

const (
	// ErrorNone indicates there was no query error.
	ErrorNone ErrorKind = iota
	// ErrorNetwork covers timeouts, temporary network failures, or unreachable hosts.
	ErrorNetwork
	// ErrorCanceled covers context cancellation or deadline exceeded.
	ErrorCanceled
	// ErrorOther covers non-network errors (invalid query, parse errors, etc.).
	ErrorOther
)

type KeyParts

type KeyParts struct {
	ServerAddr string
	Name       string
	Qtype      string
	Qclass     string
	DNSSEC     bool
	Recurse    bool
	UseVC      bool

	EDNSSize    int
	EDNSVersion *uint8
	EDNSZ       *uint16
	EDNSRcode   *uint8
	EDNSData    []dns.EDNS0
}

KeyParts defines the granularity for global DNS query caching. The key is intentionally sensitive to transport and EDNS settings, since they can affect response size, truncation, and DNSSEC behavior.

type Result

type Result struct {
	HasResponse bool
	ErrorKind   ErrorKind
}

Result summarizes a DNS query outcome for cache decisions. HasResponse means the resolver received a DNS response message. ErrorKind classifies the error when HasResponse is false.

Jump to

Keyboard shortcuts

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