cache

package
v0.0.0-...-4829b00 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 8 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, redisUrl string, cacheRedisConnectionPoolSize 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 local dns cache information for debugging

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 will be 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) InsertMessageToLocal

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

func (*Cache) InsertMessageToRedis

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

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.

func (*Cache) SearchFromLocal

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

todo: use finder implementation

func (*Cache) SearchFromRedis

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

Jump to

Keyboard shortcuts

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