cache

package
v0.0.0-...-1d29830 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Entries map[string]Entry
	// contains filtered or unexported fields
}

Cache object

func NewCache

func NewCache(cfg config.Config) *Cache

NewCache returns a new cache instance

Example
package main

import (
	"github.com/dvlahovski/go-dnscached/cache"
	"github.com/dvlahovski/go-dnscached/config"
)

func main() {
	config, err := config.Load("../config/config.json")
	if err != nil {
		return
	}

	_ = cache.NewCache(*config)
}
Output:

func (*Cache) Delete

func (c *Cache) Delete(key string) bool

Delete an entry

func (*Cache) Get

func (c *Cache) Get(key string) (dns.Msg, bool)

Get a DNS msg from the cache

func (*Cache) GetEntry

func (c *Cache) GetEntry(key string) (Entry, bool)

GetEntry returns the internal entry

func (*Cache) Insert

func (c *Cache) Insert(key string, value dns.Msg) bool

Insert a DNS msg in the cache

Example
package main

import (
	"fmt"

	"github.com/dvlahovski/go-dnscached/cache"
	"github.com/dvlahovski/go-dnscached/config"
	"github.com/miekg/dns"
)

func main() {
	config, err := config.Load("../config/config.json")
	if err != nil {
		return
	}

	cache := cache.NewCache(*config)
	ok := cache.Insert("google.bg", dns.Msg{})

	if !ok {
		fmt.Printf("insertion failed")
	}
}
Output:

func (*Cache) InsertFromParams

func (c *Cache) InsertFromParams(key string, ip string, recordType uint16, ttl int) bool

InsertFromParams - insert and entry from separate params

Example
package main

import (
	"fmt"

	"github.com/dvlahovski/go-dnscached/cache"
	"github.com/dvlahovski/go-dnscached/config"
	"github.com/miekg/dns"
)

func main() {
	config, err := config.Load("../config/config.json")
	if err != nil {
		return
	}

	cache := cache.NewCache(*config)
	ok := cache.InsertFromParams("google.bg", "1.2.3.4", dns.TypeA, 120)
	fmt.Printf("%t\n", ok)
}
Output:

true

func (*Cache) MarshalJSON

func (c *Cache) MarshalJSON() ([]byte, error)

MarshalJSON returns a json representation of the cache's contents

type Entry

type Entry struct {
	Value dns.Msg
	// contains filtered or unexported fields
}

Entry is the cache's internal entry representation

func (Entry) MarshalJSON

func (e Entry) MarshalJSON() ([]byte, error)

func (Entry) ToStringEntry

func (e Entry) ToStringEntry() StringEntry

type StringEntry

type StringEntry struct {
	Key   string
	Value []string
	Ttl   int
	Type  string
}

Jump to

Keyboard shortcuts

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