dcache

package module
v0.0.0-...-9367a60 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

README

dcache

CoreDNS Plugin: Asynchronous Distributed Cache for Distributed System.

Name

dcache - enables a networked async cache using Redis Pub/Sub.

dcache is a [d]istributed [cache] plugin.

Description

Using dcache, you can use Redis Pub/Sub to asynchronously share name resolution resolved by other nodes. This means that DNS queries do not use unnecessary communication to retrieve the cache, and it operates with very low latency. It can be used in conjunction with the CoreDNS standard cache plug-in. The TTL of the cache is the smallest value in the response.

If this plugin is enabled and you cannot connect to Redis, it does nothing and does not interfere with CoreDNS operation.

What is the difference from redisc?

redisc takes the data to Redis after a DNS query, but dcache uses Pub/Sub to keep the cache data in memory asynchronously.

dcache provides better latency than redisc in environments with very large DNS queries such as crawling.

Config

Example

all zone enable dcache.

. {
    forward . 1.1.1.1
    cache
    dcache example.org:6379
}
syntax

dcache [Redishost]:[Port]

Metrics

If monitoring is enabled (via the prometheus directive) then the following metrics are exported:

  • coredns_dcache_hits_total{server} - Counter of cache hits.
  • coredns_dcache_misses_total{server} - Counter of cache misses.
  • coredns_dcache_redis_errors_total{server} - Counter of errors when connecting to Redis.
  • coredns_dcache_discard_cache_total{server} - Counter of data that failed deserialization.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnswerCache

type AnswerCache struct {
	Name      string   `json:"name"`
	Response  *dns.Msg `json:"response"`
	Type      dns.Type `json:"type"`
	Do        bool     `json:"do"`
	TimeToDie int64    `json:"time_to_die"`
	By        string   `json:"by"`
	Error     bool
}

func (*AnswerCache) MarshalJSON

func (a *AnswerCache) MarshalJSON() ([]byte, error)

func (*AnswerCache) UnmarshalJSON

func (a *AnswerCache) UnmarshalJSON(data []byte) error

type CacheRepository

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

func NewCacheRepository

func NewCacheRepository(size int) (*CacheRepository, error)

func (*CacheRepository) Get

func (c *CacheRepository) Get(now int64, r *request.Request) (*AnswerCache, bool)

func (*CacheRepository) Set

func (c *CacheRepository) Set(msg *AnswerCache) error

type Dcache

type Dcache struct {
	Addr string
	Next plugin.Handler
	// contains filtered or unexported fields
}

Dcache is a plugin that distribute shard successCache.

func New

func New(host string) *Dcache

func (*Dcache) Name

func (d *Dcache) Name() string

Name implements the Handler interface.

func (*Dcache) ServeDNS

func (d *Dcache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

type ResponseWriter

type ResponseWriter struct {
	dns.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponsePrinter

func NewResponsePrinter(w dns.ResponseWriter, log clog.P, d *Dcache, state request.Request) *ResponseWriter

NewResponsePrinter returns ResponseWriter.

func (*ResponseWriter) RemoteAddr

func (r *ResponseWriter) RemoteAddr() net.Addr

RemoteAddr implements the dns.ResponseWriter interface.

func (*ResponseWriter) WriteMsg

func (r *ResponseWriter) WriteMsg(res *dns.Msg) error

WriteMsg calls the underlying ResponseWriter's WriteMsg method and prints "example" to standard output.

Jump to

Keyboard shortcuts

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