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 ¶
- Variables
- type Cache
- type FileStore
- func (s FileStore) List(ctx context.Context, prefix string) iter.Seq2[string, error]
- func (s FileStore) Load(ctx context.Context, key string) ([]byte, error)
- func (s FileStore) Remove(ctx context.Context, key string) error
- func (s FileStore) Store(ctx context.Context, key string, value []byte) error
- type Store
Constants ¶
This section is empty.
Variables ¶
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 ¶
NewCache constructs a new empty Cache from the given Store. It will panic if s == nil.
func (*Cache) Load ¶
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.
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.
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.