Documentation
¶
Index ¶
- func AcquireMsg() *dns.Msg
- func ReleaseMsg(m *dns.Msg)
- func SetCacheSizeFuncs(positive, negative func() int)
- func SetMetricsInstance(m *CacheMetrics)
- func UpdateCacheSizeMetrics()
- type Cache
- type CacheConfig
- type CacheEntry
- type CacheKey
- type CacheMetrics
- type DNSCache
- type NegativeCache
- type PositiveCache
- type PrefetchQueue
- type PrefetchRequest
- type ResponseWriter
- type TTLManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireMsg ¶ added in v1.0.0
AcquireMsg returns an empty msg from pool with pre-allocated slices.
func SetCacheSizeFuncs ¶ added in v1.6.1
func SetCacheSizeFuncs(positive, negative func() int)
SetCacheSizeFuncs sets the functions to get cache sizes
func SetMetricsInstance ¶ added in v1.6.1
func SetMetricsInstance(m *CacheMetrics)
SetMetricsInstance sets the metrics instance for hit rate calculation
func UpdateCacheSizeMetrics ¶ added in v1.6.1
func UpdateCacheSizeMetrics()
UpdateCacheSizeMetrics updates the cache size gauges
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the cache implementation.
func (*Cache) ServeDNS ¶
func (c *Cache) ServeDNS(ctx context.Context, ch *middleware.Chain)
(*Cache).ServeDNS serveDNS implements the middleware.Handler interface.
func (*Cache) Set ¶
(*Cache).Set set adds a new element to the cache. Provided for API compatibility.
type CacheConfig ¶ added in v1.5.0
type CacheConfig struct {
Size int
Prefetch int
PositiveTTL time.Duration
NegativeTTL time.Duration
MinTTL time.Duration
MaxTTL time.Duration
RateLimit int
}
CacheConfig holds cache configuration with validation.
func (CacheConfig) Validate ¶ added in v1.5.0
func (cc CacheConfig) Validate() error
(CacheConfig).Validate validate checks if the configuration is valid.
type CacheEntry ¶ added in v1.5.0
type CacheEntry struct {
// contains filtered or unexported fields
}
CacheEntry represents an immutable cache entry.
func NewCacheEntry ¶ added in v1.5.0
NewCacheEntry creates a new cache entry from a DNS message.
func NewCacheEntryWithKey ¶ added in v1.6.0
NewCacheEntryWithKey creates a new cache entry with a specific key for rate limiting
func (*CacheEntry) GetRateLimiter ¶ added in v1.6.0
func (e *CacheEntry) GetRateLimiter() *rate.Limiter
(*CacheEntry).GetRateLimiter returns the shared rate limiter for this entry
func (*CacheEntry) IsExpired ¶ added in v1.5.0
func (e *CacheEntry) IsExpired() bool
(*CacheEntry).IsExpired isExpired checks if the cache entry has expired.
func (*CacheEntry) ShouldPrefetch ¶ added in v1.5.0
func (e *CacheEntry) ShouldPrefetch(threshold int) bool
(*CacheEntry).ShouldPrefetch shouldPrefetch checks if this entry should be prefetched.
func (*CacheEntry) TTL ¶ added in v1.5.0
func (e *CacheEntry) TTL() int
(*CacheEntry).TTL TTL returns the remaining TTL in seconds.
type CacheMetrics ¶ added in v1.5.0
type CacheMetrics struct {
// contains filtered or unexported fields
}
CacheMetrics tracks cache performance metrics.
func (*CacheMetrics) Eviction ¶ added in v1.5.0
func (m *CacheMetrics) Eviction()
(*CacheMetrics).Eviction eviction records a cache eviction.
func (*CacheMetrics) Hit ¶ added in v1.5.0
func (m *CacheMetrics) Hit()
(*CacheMetrics).Hit hit records a cache hit.
func (*CacheMetrics) Miss ¶ added in v1.5.0
func (m *CacheMetrics) Miss()
(*CacheMetrics).Miss miss records a cache miss.
func (*CacheMetrics) Prefetch ¶ added in v1.5.0
func (m *CacheMetrics) Prefetch()
(*CacheMetrics).Prefetch prefetch records a prefetch operation.
func (*CacheMetrics) Stats ¶ added in v1.5.0
func (m *CacheMetrics) Stats() (hits, misses, evictions, prefetches int64)
(*CacheMetrics).Stats stats returns current metrics.
type DNSCache ¶ added in v1.5.0
type DNSCache interface {
Get(key uint64) (*CacheEntry, bool)
Set(key uint64, entry *CacheEntry)
Remove(key uint64)
Len() int
}
DNSCache defines the interface for DNS cache implementations.
type NegativeCache ¶ added in v1.5.0
type NegativeCache struct {
// contains filtered or unexported fields
}
NegativeCache handles error DNS responses.
func NewNegativeCache ¶ added in v1.5.0
func NewNegativeCache(size int, minTTL, maxTTL time.Duration, metrics *CacheMetrics) *NegativeCache
NewNegativeCache creates a new negative cache.
func (*NegativeCache) Get ¶ added in v1.5.0
func (nc *NegativeCache) Get(key uint64) (*CacheEntry, bool)
(*NegativeCache).Get get retrieves an entry from the negative cache.
func (*NegativeCache) Len ¶ added in v1.5.0
func (nc *NegativeCache) Len() int
(*NegativeCache).Len len returns the number of entries in the cache.
func (*NegativeCache) Remove ¶ added in v1.5.0
func (nc *NegativeCache) Remove(key uint64)
(*NegativeCache).Remove remove deletes an entry from the negative cache.
func (*NegativeCache) Set ¶ added in v1.5.0
func (nc *NegativeCache) Set(key uint64, entry *CacheEntry)
(*NegativeCache).Set set stores an entry in the negative cache.
type PositiveCache ¶ added in v1.5.0
type PositiveCache struct {
// contains filtered or unexported fields
}
PositiveCache handles successful DNS responses.
func NewPositiveCache ¶ added in v1.5.0
func NewPositiveCache(size int, minTTL, maxTTL time.Duration, metrics *CacheMetrics) *PositiveCache
NewPositiveCache creates a new positive cache.
func (*PositiveCache) Get ¶ added in v1.5.0
func (pc *PositiveCache) Get(key uint64) (*CacheEntry, bool)
(*PositiveCache).Get get retrieves an entry from the positive cache.
func (*PositiveCache) Len ¶ added in v1.5.0
func (pc *PositiveCache) Len() int
(*PositiveCache).Len len returns the number of entries in the cache.
func (*PositiveCache) Remove ¶ added in v1.5.0
func (pc *PositiveCache) Remove(key uint64)
(*PositiveCache).Remove remove deletes an entry from the positive cache.
func (*PositiveCache) Set ¶ added in v1.5.0
func (pc *PositiveCache) Set(key uint64, entry *CacheEntry)
(*PositiveCache).Set set stores an entry in the positive cache.
type PrefetchQueue ¶ added in v1.5.0
type PrefetchQueue struct {
// contains filtered or unexported fields
}
PrefetchQueue manages prefetch requests with worker pool.
func NewPrefetchQueue ¶ added in v1.5.0
func NewPrefetchQueue(workers, queueSize int, metrics *CacheMetrics) *PrefetchQueue
NewPrefetchQueue creates a new prefetch queue.
func (*PrefetchQueue) Add ¶ added in v1.5.0
func (pq *PrefetchQueue) Add(req PrefetchRequest) bool
(*PrefetchQueue).Add add queues a prefetch request.
func (*PrefetchQueue) Stop ¶ added in v1.5.0
func (pq *PrefetchQueue) Stop()
(*PrefetchQueue).Stop stop gracefully shuts down the prefetch queue.
type PrefetchRequest ¶ added in v1.5.0
type PrefetchRequest struct {
Request *dns.Msg
Key uint64
Cache *Cache // Reference to the cache to store prefetched results
}
PrefetchRequest represents a DNS query to be prefetched.
type ResponseWriter ¶
type ResponseWriter struct {
middleware.ResponseWriter
// contains filtered or unexported fields
}
ResponseWriter is the response writer for cache.
type TTLManager ¶ added in v1.5.0
type TTLManager struct {
// contains filtered or unexported fields
}
TTLManager manages TTL calculations.
func NewTTLManager ¶ added in v1.5.0
func NewTTLManager(min, max time.Duration) TTLManager
NewTTLManager creates a new TTL manager.