msgcache

package
v0.5.26 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Name

msgcache - cache DNS messages

Description

With msgcache messages are cached for faster retrieval. The responses code on responses will be checked as msgcache will only cache RcodeNameError and RcodeSuccess. Items will be cached for a minimum of 600 seconds (5 minutes), or their actual TTL with a maximum of a week (604800 seconds). After that they are evicted from the cache. For each cached elements a random jitter of up to 2 hours is added.

Syntax

msgcache

Examples

The dbsqlite handler needs round trips to the database which slows things down, to make it faster you can deploy the cache in front of it:

example.org {
    msgcache
    dbsqlite example.org.db
}

Bugs

This handler is not deemed ready yet.

Design

The msgcache caches nodes that are build up as follows, in brackets are the Go types:

Name     [string]
Rcode    [uint16
Time     [time.Time]
Answer   [[]dns.RR]
Ns       [[]dns.RR]
Extra    [[]dns.RR]

From bottom to top. Answer, Ns, and Extra contains the read-only part of the message. These can be copied as-is and don't need to be deep copied out of the cache. Time is the timestamp of when this partical node was added, this is used for purging the msgcache. Rcode is the response code of the message, only RcodeNameError is of importance here, if such a node is found, there can't be anything below that name. Name is the name of the node, this was the original query that lead to this reponse being cached.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Err

func Err(err error) slog.Attr

func Less

func Less(a, b Node) bool

Less compares nodes a, b by Name and returns true if a is less than b.

Types

type Msgcache

type Msgcache struct {
	Tree *btree.BTreeG[Node]
}

func (*Msgcache) Delete

func (m *Msgcache) Delete(name string) bool

Delete removes a node from the store.

func (*Msgcache) Dump

func (m *Msgcache) Dump()

func (*Msgcache) Err

func (h *Msgcache) Err(err error) error

func (*Msgcache) Evict

func (m *Msgcache) Evict()

Evict walks the msgcache and creates a list of maximum 10 items to delete. After the walk host itmes are eviects.

func (*Msgcache) Get

func (m *Msgcache) Get(name string) (Node, bool)

Get gets the node under name from the store.

func (*Msgcache) HandlerFunc

func (m *Msgcache) HandlerFunc(next dns.HandlerFunc) dns.HandlerFunc

func (*Msgcache) Key

func (h *Msgcache) Key() string

func (*Msgcache) NodeFound

func (m *Msgcache) NodeFound(x *dns.Msg, node Node) *dns.Msg

func (*Msgcache) Retrieve

func (m *Msgcache) Retrieve(x *dns.Msg) *dns.Msg

func (*Msgcache) Set

func (m *Msgcache) Set(x *dns.Msg) string

Set sets the node under name from the store. If successful it return the name, otherwise the empty string.

func (*Msgcache) Setup

func (m *Msgcache) Setup(co *dnsserver.Controller) error

type Node

type Node struct {
	Name   string
	Type   uint16
	Rcode  uint16
	Time   time.Time
	Answer []dns.RR
	Ns     []dns.RR
	Extra  []dns.RR
}

A node is stored in the store.

Jump to

Keyboard shortcuts

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