netmapcache

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

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

Go to latest
Published: Feb 9, 2026 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Overview

Package netmapcache implements a persistent cache for netmap.NetworkMap values, allowing a client to start up using stale but previously-valid state even if a connection to the control plane is not immediately available.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrKeyNotFound is a sentinel error reported by implementations of the [Store]
	// interface when loading a key that is not found in the store.
	ErrKeyNotFound = errors.New("storage key not found")

	// ErrCacheNotAvailable is a sentinel error reported by cache methods when
	// the netmap caching feature is not enabled in the build.
	ErrCacheNotAvailable = errors.New("netmap cache is not available")
)

Functions

This section is empty.

Types

type Cache

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

A Cache manages a columnar cache of a netmap.NetworkMap. Each Cache holds a single netmap value; use Cache.Store to update or replace the cached value and Cache.Load to read the cached value.

func NewCache

func NewCache(s Store) *Cache

NewCache constructs a new empty Cache from the given Store. It will panic if s == nil.

func (*Cache) Load

func (c *Cache) Load(ctx context.Context) (*netmap.NetworkMap, error)

Load loads the cached netmap.NetworkMap value stored in c, if one is available. It reports ErrCacheNotAvailable if no cached data are available. On success, the Cached field of the returned network map is true.

func (*Cache) Store

func (c *Cache) Store(ctx context.Context, nm *netmap.NetworkMap) error

Store records nm in the cache, replacing any previously-cached values.

type FileStore

type FileStore string

FileStore implements the Store interface using a directory of files, in which each key is encoded as a filename in the directory. The caller is responsible to ensure the directory path exists before using the store methods.

func (FileStore) List

func (s FileStore) List(ctx context.Context, prefix string) iter.Seq2[string, error]

List implements part of the Store interface.

func (FileStore) Load

func (s FileStore) Load(ctx context.Context, key string) ([]byte, error)

Load implements part of the Store interface.

func (FileStore) Remove

func (s FileStore) Remove(ctx context.Context, key string) error

Remove implements part of the Store interface.

func (FileStore) Store

func (s FileStore) Store(ctx context.Context, key string, value []byte) error

Store implements part of the Store interface.

type Store

type Store interface {
	// List lists all the stored keys having the specified prefixes, in
	// lexicographic order.
	//
	// Each pair yielded by the iterator is either a valid storage key and a nil
	// error, or an empty key and a non-nil error. After reporting an error, the
	// iterator must immediately return.
	List(ctx context.Context, prefix string) iter.Seq2[string, error]

	// Load fetches the contents of the specified key.
	// If the key is not found in the store, Load must report [ErrKeyNotFound].
	Load(ctx context.Context, key string) ([]byte, error)

	// Store marshals and stores the contents of the specified value under key.
	// If the key already exists, its contents are replaced.
	Store(ctx context.Context, key string, value []byte) error

	// Remove removes the specified key from the store. If the key does not exist,
	// Remove reports success (nil).
	Remove(ctx context.Context, key string) error
}

Store is the interface to persistent key-value storage used by a Cache.

Jump to

Keyboard shortcuts

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