Documentation ¶
Index ¶
- Variables
- type Object
- type ObjectIterator
- type ObjectStore
- func (st *ObjectStore) Close() error
- func (st *ObjectStore) Delete(key string) error
- func (st *ObjectStore) Get(key string, dst Object) error
- func (st *ObjectStore) Has(key string) (bool, error)
- func (st *ObjectStore) Iterator(matchFn func(string) bool) (*ObjectIterator, error)
- func (st *ObjectStore) Lock(key string) (unlock func())
- func (st *ObjectStore) Put(key string, src Object) error
- func (st *ObjectStore) RLock(key string) (runlock func())
- func (st *ObjectStore) Read() *StateRO
- func (st *ObjectStore) ReadFn(fn func(*StateRO))
- func (st *ObjectStore) Update() *StateRW
- func (st *ObjectStore) UpdateFn(fn func(*StateRW))
- type StateRO
- type StateRW
Constants ¶
This section is empty.
Variables ¶
var ErrIteratorClosed = errors.New("store/object: iterator closed")
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 (*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
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