object

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIteratorClosed = errors.New("store/object: iterator closed")
View Source
var ErrStateClosed = errors.New("store/object: state closed")

Functions

This section is empty.

Types

type Object

type Object interface {
	// Copy should return a copy of the current object
	Copy() Object

	// Set should attempt to set the current object details to the supplied
	Set(Object) error

	// Marshal should attempt to serialize a binary representation of the object
	Marshal() ([]byte, error)

	// Unmarshal should attempt to deserialize from a binary representation
	Unmarshal([]byte) error
}

Object defines a (de)serializable object

type ObjectIterator

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

ObjectIterator provides an iterator to all the key-value pairs in an ObjectStore. While the iterator is open the store will be read locked, you MUST release the iterator when you are finished with it.

Please note: - as this iterator only acquires a store read-lock, any values loaded from disk will NOT be cached - individual iterators are NOT concurrency safe, though it is safe to have multiple iterators running concurrently

func (*ObjectIterator) Key

func (i *ObjectIterator) Key() string

Key returns the next key from the store

func (*ObjectIterator) Next

func (i *ObjectIterator) Next() bool

Next attempts to set the next key-value pair, the return value is if there was another pair remaining

func (*ObjectIterator) Release

func (i *ObjectIterator) Release()

Release releases the ObjectIterator and ObjectStore's read lock

func (*ObjectIterator) Value

func (i *ObjectIterator) Value(dst Object) error

Value attempts to load the next object in the ObjectStore into the supplied destination

type ObjectStore

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

ObjectStore provides a key-value store for serializable objects, persisting their serialized form to disk in the same manner that KVStore performs, but storing deserialized objects in a TTL cache to reduce the performance impact of constant serializing / deserializing

func OpenBlock

func OpenBlock(path string, cfg *storage.BlockConfig, ttl time.Duration) (*ObjectStore, error)

func OpenFile

func OpenFile(path string, cfg *storage.DiskConfig, ttl time.Duration) (*ObjectStore, error)

func OpenStorage

func OpenStorage(storage storage.Storage, ttl time.Duration) (*ObjectStore, error)

func (*ObjectStore) Close added in v1.3.0

func (st *ObjectStore) Close() error

Close will close the underlying storage, the mutex map locking (e.g. RLock(), Lock() will still work).

func (*ObjectStore) Delete

func (st *ObjectStore) Delete(key string) error

Delete removes the key-object pair from the store

func (*ObjectStore) Get

func (st *ObjectStore) Get(key string, dst Object) error

Get will fetch and load the object at key into the supplied destination obj

func (*ObjectStore) Has

func (st *ObjectStore) Has(key string) (bool, error)

Has checks if a key exists in the store

func (*ObjectStore) Iterator

func (st *ObjectStore) Iterator(matchFn func(string) bool) (*ObjectIterator, error)

Iterator returns an Iterator for key-object pairs in the store, using supplied match function

func (*ObjectStore) Lock added in v1.2.0

func (st *ObjectStore) Lock(key string) (unlock func())

Lock acquires a write-lock on supplied key, returning unlock function.

func (*ObjectStore) Put

func (st *ObjectStore) Put(key string, src Object) error

Put will place the supplied source object into the store at the key location

func (*ObjectStore) RLock added in v1.2.0

func (st *ObjectStore) RLock(key string) (runlock func())

RLock acquires a read-lock on supplied key, returning unlock function.

func (*ObjectStore) Read

func (st *ObjectStore) Read() *StateRO

func (*ObjectStore) ReadFn added in v1.1.4

func (st *ObjectStore) ReadFn(fn func(*StateRO))

func (*ObjectStore) Update

func (st *ObjectStore) Update() *StateRW

func (*ObjectStore) UpdateFn added in v1.1.4

func (st *ObjectStore) UpdateFn(fn func(*StateRW))

type StateRO

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

StateRO provides a read-only window to the store. While this state is active during the Read() function window, the entire store will be read-locked. The state is thread-safe for concurrent use UNTIL the moment that your supplied function to Read() returns, then the state has zero guarantees

func (*StateRO) Get

func (st *StateRO) Get(key string, dst Object) error

func (*StateRO) Has

func (st *StateRO) Has(key string) (bool, error)

func (*StateRO) Release added in v1.1.4

func (st *StateRO) Release()

type StateRW

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

StateRW provides a read-write window to the store. While this state is active during the Update() function window, the entire store will be locked. The state is thread-safe for concurrent use UNTIL the moment that your supplied function to Update() returns, then the state has zero guarantees

func (*StateRW) Delete

func (st *StateRW) Delete(key string) error

func (*StateRW) Get

func (st *StateRW) Get(key string, dst Object) error

func (*StateRW) Has

func (st *StateRW) Has(key string) (bool, error)

func (*StateRW) Put

func (st *StateRW) Put(key string, src Object) error

func (*StateRW) Release added in v1.1.4

func (st *StateRW) Release()

Jump to

Keyboard shortcuts

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