cache

package
Version: v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package cache implements dns cache feature with edns-client-subnet support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(q dns.Question, ednsIP string) string

Key creates a hash key from a question section.

Types

type Cache

type Cache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Cache is a cache that holds on the a number of RRs or DNS messages. The cache eviction is randomized.

func New

func New(capacity int) *Cache

New returns a new cache with the capacity and the ttl specified.

func (*Cache) Capacity

func (c *Cache) Capacity() int

func (*Cache) Dump

func (c *Cache) Dump(nobody bool) (rs map[string][]string, l int)

Dump returns all dns cache information, for dubugging

func (*Cache) EvictRandom

func (c *Cache) EvictRandom()

EvictRandom removes a random member a the cache. Must be called under a write lock.

func (*Cache) Hit

func (c *Cache) Hit(key string, msgid uint16) *dns.Msg

Hit returns a dns message from the cache. If the message's TTL is expired nil is returned and the message is removed from the cache.

func (*Cache) InsertMessage

func (c *Cache) InsertMessage(s string, m *dns.Msg, mTTL uint32)

InsertMessage inserts a message in the Cache. We will cache it for ttl seconds, which should be a small (60...300) integer.

func (*Cache) Remove

func (c *Cache) Remove(s string)

func (*Cache) Search

func (c *Cache) Search(s string) (*dns.Msg, time.Time, bool)

Search returns a dns.Msg, the expiration time and a boolean indicating if we found something in the cache. todo: use finder implementation

Source Files

Jump to

Keyboard shortcuts

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