cache

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2025 License: GPL-3.0, MIT Imports: 14 Imported by: 0

Documentation

Overview

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

	All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Copyright © 2025 M.Watermann, 10247 Berlin, Germany

    All rights reserved
EMail : <[email protected]>

Index

Constants

View Source
const (
	// `CacheTypeMap` is a map-based cache list.
	CacheTypeMap = TCacheType(-1)

	// `CacheTypeTrie` is a trie-based cache list.
	CacheTypeTrie = TCacheType(1)

	// `DefaultCacheSize` is the initial size of the cache list.
	DefaultCacheSize = 1 << 10 // 1024

	// `DefaultTTL` is the default time to live for a DNS cache entry.
	DefaultTTL = time.Duration(time.Minute << 9) // ~8 hours
)

Variables

View Source
var (
	// `ErrNodeNil` is returned if a node or a method's required
	// argument is `nil`.
	ErrNodeNil = errors.New("node or argument is nil")
)

Functions

This section is empty.

Types

type ICacheList added in v0.11.1

type ICacheList interface {

	// `AutoExpire()` removes expired cache entries at a given interval.
	//
	// Parameters:
	//   - `time.Duration`: Time interval to refresh the cache.
	//   - `chan struct{}`: Channel to receive a signal to abort.
	AutoExpire(time.Duration, chan struct{})

	// `Clone()` creates a deep copy of the cache list.
	//
	// Returns:
	//   - `ICacheList`: A deep copy of the cache list.
	Clone() ICacheList

	// `Create()` adds a new cache entry for the given hostname.
	//
	// Parameters:
	//   - `context.Context`: Timeout context to use for the operation.
	//   - `string`: The hostname to add a cache entry for.
	//   - `[]net.IP`: List of IP addresses to add to the cache entry.
	//   - `time.Duration`: Time to live for the hostname's cache entry.
	//
	// Returns:
	//   - `ICacheList`: The updated cache list.
	Create(context.Context, string, []net.IP, time.Duration) ICacheList

	// `Delete()` removes a hostname pattern from the node's trie.
	//
	// The method returns `true` if at least one part of the
	// hostname's path was deleted, `false` otherwise.
	//
	// Parameters:
	//   - `context.Context`: Timeout context to use for the operation.
	//   - `string`: The hostname to remove from the cache.
	//
	// Returns:
	//   - `bool`: `true` if a node was deleted, `false` otherwise.
	Delete(context.Context, string) bool

	// `Exists()` checks whether the given hostname is cached.
	//
	// Parameters:
	//   - `context.Context`: Timeout context to use for the operation.
	//   - `string`: The hostname to check for.
	//
	// Returns:
	//   - `bool`: `true` if the hostname was found in the cache, `false` otherwise.
	Exists(context.Context, string) bool

	// `IPs()` returns the IP addresses for the given hostname.
	//
	// Parameters:
	//   - `context.Context`: Timeout context to use for the operation.
	//   - `string`: The hostname to lookup in the cache.
	//
	// Returns:
	//   - `[]net.IP`: List of IP addresses for the given hostname.
	//   - `bool`: `true` if the hostname was found in the cache, `false` otherwise.
	IPs(context.Context, string) ([]net.IP, bool)

	// `Len()` returns the number of cached hostnames.
	//
	// Returns:
	//   - `int`: Number of cached hostnames.
	Len() int

	// `Range()` returns a channel that yields all FQDNs in sorted order.
	//
	// Usage: for fqdn := range ICacheList.Range() { ... }
	//
	// The channel is closed automatically when all entries have been yielded.
	//
	// Parameters:
	//   - `context.Context`: Timeout context to use for the operation.
	//
	// Returns:
	//   - `chan string`: Channel that yields all FQDNs in sorted order.
	Range(context.Context) <-chan string

	// `Update()` updates the cache entry with the given IP addresses.
	//
	// Parameters:
	//   - `context.Context`: Timeout context to use for the operation.
	//   - `string`: The hostname to lookup in the cache.
	//   - `[]net.IP`: List of IP addresses to update the cache entry with.
	//   - `time.Duration`: Time to live for the cache entry.
	//
	// Returns:
	//   - `ICacheList`: The updated cache list.
	Update(context.Context, string, []net.IP, time.Duration) ICacheList
}

`ICacheList` is the basic interface for a cache list. It provides a CRUD interface for caching hostname's IP addresses:

  • `C`: Create a new hostname's data cache [Create],
  • `R`: Retrieve a hostname's cached data [IPs],
  • `U`: Update a hostname's cached data [Update],
  • `D`: Delete a hostname's cached data [Delete].

func New added in v0.11.1

func New(aType TCacheType, aSize uint) ICacheList

`New()` returns a new IP address cache list.

There are currently two types of cache lists available:

  • `CacheTypeMap`: A map-based cache list,
  • `CacheTypeTrie`: A trie-based cache list.

The cache type is determined by the `aType` parameter. The trie-based cache is the default.

The `aSize` argument is relevant only for the map-based cache list. If the value is zero, the default size (`1024`) is used.

Parameters:

  • `aType`: Type of cache to create.
  • `aSize`: Initial size of the map-based cache.

Returns:

  • `ICacheList`: A new IP address cache list.

type TCacheType added in v0.11.1

type TCacheType int8

`TCacheType` is the type of cache list to create.

Jump to

Keyboard shortcuts

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