cache

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BadgerCache

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

BadgerCache wraps BadgerDB for DNS query caching

func NewBadgerCache

func NewBadgerCache(dataPath string, log logger.Logger) (*BadgerCache, error)

NewBadgerCache creates a new BadgerDB cache instance with optimized settings for embedded devices

func (*BadgerCache) Close

func (bc *BadgerCache) Close() error

Close closes the BadgerDB instance

func (*BadgerCache) Delete

func (bc *BadgerCache) Delete(key string) error

Delete removes a key from the cache

func (*BadgerCache) Get

func (bc *BadgerCache) Get(key string) (*CachedMsg, bool)

Get retrieves a DNS message from the cache

func (*BadgerCache) Set

func (bc *BadgerCache) Set(key string, msg *CachedMsg, ttl time.Duration) error

Set stores a DNS message in the cache with the given key and TTL

func (*BadgerCache) Stats

func (bc *BadgerCache) Stats() string

Stats returns cache statistics

type Cache

type Cache interface {
	Get(key string) (*CachedMsg, bool)
	Set(key string, msg *CachedMsg, ttl time.Duration) error
	Delete(key string) error
	Close() error
	Stats() string
}

Cache 定义缓存接口

type CachedMsg

type CachedMsg struct {
	Msg     *dns.Msg  `json:"msg"`
	Expires time.Time `json:"expires"`
}

CachedMsg represents a cached DNS message with expiration time

Jump to

Keyboard shortcuts

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