cache

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 6 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

Overview

Package cache stores upstream replies and serves them again until their TTL runs out, counting TTLs down so clients see the true remaining time.

Rules:

  • Only NOERROR and NXDOMAIN replies are cached, and never truncated ones.
  • Positive answers live for the smallest TTL in the reply.
  • Negative answers (NXDOMAIN, or NOERROR with no answer) live for min(SOA TTL, SOA MINIMUM), per RFC 2308 section 5. Without an SOA they are not cached.
  • When full, the least recently used entry is evicted.

A nil *Cache is valid and caches nothing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func New

func New(maxEntries int, maxTTL time.Duration) *Cache

New returns a cache holding at most maxEntries replies, none kept longer than maxTTL however long their records say.

func (*Cache) Get

func (c *Cache) Get(q *dnsmsg.Query, now time.Time, maxSize int) ([]byte, bool)

Get returns a cached reply rewritten for q: q's ID, q's question bytes (keeping the client's letter case), and TTLs reduced by the time spent in the cache. maxSize is the largest reply the client can receive; a cached reply bigger than that is not served.

func (*Cache) Len

func (c *Cache) Len() int

Len reports how many replies are stored, expired ones included until they are next looked up.

func (*Cache) Put

func (c *Cache) Put(q *dnsmsg.Query, resp []byte, now time.Time) bool

Put stores resp as the answer to q. Returns whether it was cached.

type Key

type Key struct {
	Name  string
	Type  uint16
	Class uint16
	EDNS  bool
	DO    bool
	CD    bool
}

Key identifies which replies are interchangeable. EDNS and the DNSSEC bits change what the upstream sends back, so they are part of the key.

func KeyFor

func KeyFor(q *dnsmsg.Query) Key

Jump to

Keyboard shortcuts

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