Documentation
¶
Overview ¶
Package cache provides DNS caching functionality for SDNS.
Index ¶
- Variables
- func Key(q dns.Question, cd ...bool) uint64
- func KeySimple(q dns.Question, cd ...bool) uint64
- func KeyString(qname string, qtype, qclass uint16, cd bool) uint64
- type Cache
- type Pair
- type SegmentUInt64Map
- func (m *SegmentUInt64Map[V]) All() iter.Seq2[uint64, V]
- func (m *SegmentUInt64Map[V]) Clear()
- func (m *SegmentUInt64Map[V]) Del(key uint64) bool
- func (m *SegmentUInt64Map[V]) ForEach(f func(uint64, V) bool)
- func (m *SegmentUInt64Map[V]) Get(key uint64) (V, bool)
- func (m *SegmentUInt64Map[V]) Has(key uint64) bool
- func (m *SegmentUInt64Map[V]) Keys() iter.Seq[uint64]
- func (m *SegmentUInt64Map[V]) Len() int64
- func (m *SegmentUInt64Map[V]) PutIfNotExists(key uint64, value V) (V, bool)
- func (m *SegmentUInt64Map[V]) Set(key uint64, value V)
- func (m *SegmentUInt64Map[V]) Values() iter.Seq[V]
- type SyncUInt64Map
- func (m *SyncUInt64Map[V]) All() iter.Seq2[uint64, V]
- func (m *SyncUInt64Map[V]) Compact() int
- func (m *SyncUInt64Map[V]) Del(key uint64) bool
- func (m *SyncUInt64Map[V]) ForEach(f func(uint64, V) bool)
- func (m *SyncUInt64Map[V]) Get(key uint64) (V, bool)
- func (m *SyncUInt64Map[V]) Has(key uint64) bool
- func (m *SyncUInt64Map[V]) Len() int64
- func (m *SyncUInt64Map[V]) RandomSample(maxSample int) []uint64
- func (m *SyncUInt64Map[V]) Set(key uint64, value V)
- func (m *SyncUInt64Map[V]) Stop()
- type UInt64Map
- func (m *UInt64Map[V]) All() iter.Seq2[uint64, V]
- func (m *UInt64Map[V]) Clear()
- func (m *UInt64Map[V]) Del(key uint64) bool
- func (m *UInt64Map[V]) ForEach(f func(uint64, V) bool)
- func (m *UInt64Map[V]) Get(key uint64) (V, bool)
- func (m *UInt64Map[V]) Has(key uint64) bool
- func (m *UInt64Map[V]) Keys() iter.Seq[uint64]
- func (m *UInt64Map[V]) Len() int
- func (m *UInt64Map[V]) Put(key uint64, val V)
- func (m *UInt64Map[V]) PutIfNotExists(key uint64, val V) (V, bool)
- func (m *UInt64Map[V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCacheNotFound error. ErrCacheNotFound = errors.New("cache not found") // ErrCacheExpired error. ErrCacheExpired = errors.New("cache expired") )
Functions ¶
func Key ¶ added in v1.5.1
Key generates a cache key for DNS queries. This implementation uses object pooling and stack allocation to achieve zero heap allocations. The optional cd parameter indicates if the CD (Checking Disabled) bit should be included.
Types ¶
type Cache ¶ added in v0.2.4
type Cache struct {
// contains filtered or unexported fields
}
Cache is cache.
func (*Cache) Add ¶ added in v0.2.4
(*Cache).Add add adds a new element to the cache. If the element already exists it is overwritten.
type SegmentUInt64Map ¶ added in v1.6.0
type SegmentUInt64Map[V any] struct { // contains filtered or unexported fields }
SegmentUInt64Map is a fast, thread-safe map for int64 keys that uses sharding (segmentation) to reduce lock contention while maintaining the performance benefits of UInt64Map
func NewSegmentUInt64Map ¶ added in v1.6.0
func NewSegmentUInt64Map[V any](segmentPower uint8, initialCapacity int) *SegmentUInt64Map[V]
NewSegmentUInt64Map creates a new segmented map for int64 keys segmentPower controls the number of segments (2^segmentPower) initialCapacity is the initial capacity per segment
func (*SegmentUInt64Map[V]) All ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) All() iter.Seq2[uint64, V]
All returns an iterator over all key-value pairs
func (*SegmentUInt64Map[V]) Clear ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Clear()
Clear removes all entries from the map
func (*SegmentUInt64Map[V]) Del ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Del(key uint64) bool
Del removes a key from the map
func (*SegmentUInt64Map[V]) ForEach ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) ForEach(f func(uint64, V) bool)
ForEach iterates through all key-value pairs Note: The iteration is not atomic and may miss concurrent updates
func (*SegmentUInt64Map[V]) Get ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Get(key uint64) (V, bool)
Get retrieves a value by key
func (*SegmentUInt64Map[V]) Has ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Has(key uint64) bool
Has checks if a key exists in the map
func (*SegmentUInt64Map[V]) Keys ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Keys() iter.Seq[uint64]
Keys returns an iterator over all keys
func (*SegmentUInt64Map[V]) Len ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Len() int64
Len returns the number of elements in the map
func (*SegmentUInt64Map[V]) PutIfNotExists ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) PutIfNotExists(key uint64, value V) (V, bool)
PutIfNotExists adds the key-value pair only if the key doesn't already exist Returns the value and true if inserted, or existing value and false if not inserted
func (*SegmentUInt64Map[V]) Set ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Set(key uint64, value V)
Set adds or updates a key-value pair
func (*SegmentUInt64Map[V]) Values ¶ added in v1.6.0
func (m *SegmentUInt64Map[V]) Values() iter.Seq[V]
Values returns an iterator over all values
type SyncUInt64Map ¶ added in v1.5.0
type SyncUInt64Map[V any] struct { // contains filtered or unexported fields }
SyncUInt64Map wraps SegmentUInt64Map to provide the expected interface
func NewSyncUInt64Map ¶ added in v1.5.0
func NewSyncUInt64Map[V any](sizePower uint) *SyncUInt64Map[V]
NewSyncUInt64Map creates a new map
func (*SyncUInt64Map[V]) All ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) All() iter.Seq2[uint64, V]
All returns an iterator
func (*SyncUInt64Map[V]) Compact ¶ added in v1.6.0
func (m *SyncUInt64Map[V]) Compact() int
Compact is a no-op for this implementation as it handles memory efficiently
func (*SyncUInt64Map[V]) Del ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) Del(key uint64) bool
Del removes a key from the map
func (*SyncUInt64Map[V]) ForEach ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) ForEach(f func(uint64, V) bool)
ForEach iterates over all entries
func (*SyncUInt64Map[V]) Get ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) Get(key uint64) (V, bool)
Get retrieves a value by key
func (*SyncUInt64Map[V]) Has ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) Has(key uint64) bool
Has checks if a key exists
func (*SyncUInt64Map[V]) Len ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) Len() int64
Len returns the number of entries
func (*SyncUInt64Map[V]) RandomSample ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) RandomSample(maxSample int) []uint64
RandomSample returns a random sample of keys
func (*SyncUInt64Map[V]) Set ¶ added in v1.5.0
func (m *SyncUInt64Map[V]) Set(key uint64, value V)
Set adds or updates a key-value pair
func (*SyncUInt64Map[V]) Stop ¶ added in v1.6.0
func (m *SyncUInt64Map[V]) Stop()
Stop is a no-op for compatibility
type UInt64Map ¶ added in v1.6.0
type UInt64Map[V any] struct { // contains filtered or unexported fields }
UInt64Map is a specialized map for uint64 keys. It is specifically optimized for clustered keys, where keys are likely to be close to each other (e.g., sequential IDs, timestamp ranges).
func NewUInt64Map ¶ added in v1.6.0
NewUInt64Map creates a new UInt64Map with given capacity
func (*UInt64Map[V]) Clear ¶ added in v1.6.0
func (m *UInt64Map[V]) Clear()
Clear removes all items from the map
func (*UInt64Map[V]) PutIfNotExists ¶ added in v1.6.0
PutIfNotExists adds key-value pair only if key doesn't exist