cache

package
v0.0.0-...-fbfc268 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKey

func NewKey(name string, qtype, qclass uint16) uint32

NewKey creates a new cache key for the DNS name, qtype and qclass

Types

type Backend

type Backend interface {
	Set(key uint32, value Value)
	Evict(key uint32)
	Read() []Value
	Reset()
}

Backend is the interface for a cache backend. All write operations in a Cache are forwarded to a Backend.

type Cache

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

Cache is a cache of DNS messages.

func New

func New(capacity int, client dnsutil.Client) *Cache

New creates a new cache of given capacity.

If client is non-nil, the cache will prefetch expired entries in an effort to serve results faster.

If backend is non-nil:

- All cache write operations will be forward to the backend. - The backed will be used to pre-populate the cache.

func NewWithBackend

func NewWithBackend(capacity int, client dnsutil.Client, backend Backend) *Cache

NewWithBackend creates a new cache that forwards entries to backend.

func (*Cache) Close

func (c *Cache) Close() error

Close consumes any outstanding cache operations.

func (*Cache) Get

func (c *Cache) Get(key uint32) (*dns.Msg, bool)

Get returns the DNS message associated with key.

func (*Cache) List

func (c *Cache) List(n int) []Value

List returns the n most recent values in cache c.

func (*Cache) Reset

func (c *Cache) Reset()

Reset removes all values contained in cache c.

func (*Cache) Set

func (c *Cache) Set(key uint32, msg *dns.Msg)

Set associates key with the DNS message msg.

If prefetching is disabled, the message will be evicted from the cache according to its TTL.

If prefetching is enabled, the message will never be evicted, but it will be refreshed when its TTL passes.

Setting a new key in a cache that has reached its capacity will evict values in a FIFO order.

func (*Cache) Stats

func (c *Cache) Stats() Stats

Stats returns cache statistics.

type Stats

type Stats struct {
	Size         int
	Capacity     int
	PendingTasks int
}

Stats contains cache statistics.

type Value

type Value struct {
	Key       uint32
	CreatedAt time.Time
	// contains filtered or unexported fields
}

Value wraps a DNS message stored in the cache.

func Unpack

func Unpack(value string) (Value, error)

Unpack converts a string value into a Value type.

func (*Value) Answers

func (v *Value) Answers() []string

Answers returns the answers of the cached value v.

func (*Value) Pack

func (v *Value) Pack() (string, error)

Pack returns a string representation of Value v.

func (*Value) Qtype

func (v *Value) Qtype() uint16

Qtype returns the query type of the cached value v

func (*Value) Question

func (v *Value) Question() string

Question returns the first question the cached value v.

func (*Value) Rcode

func (v *Value) Rcode() int

Rcode returns the response code of the cached value v.

func (*Value) TTL

func (v *Value) TTL() time.Duration

TTL returns the time to live of the cached value v.

Jump to

Keyboard shortcuts

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