Documentation ¶
Overview ¶
Package memorydb implements the key-value database layer based on memory maps. Reference go-etherium memorydb
Index ¶
- Constants
- Variables
- func GetBeaconBestStateCachedKey() []byte
- func GetBlocksCachedKey(shardID int, numBlock int) []byte
- func GetListOutputcoinCachedKey(publicKey []byte, tokenID *common.Hash, shardID byte) []byte
- func GetListPrivacyTokenCachedKey() []byte
- func GetListPrivacyTokenCrossShardCachedKey() []byte
- func GetShardBestStateCachedKey() []byte
- type Iteratee
- type Iterator
- type MemCacheError
- type MemoryCache
- func (db *MemoryCache) Close() error
- func (db *MemoryCache) Compact(start []byte, limit []byte) error
- func (db *MemoryCache) Delete(key []byte) error
- func (db *MemoryCache) Get(key []byte) ([]byte, error)
- func (db *MemoryCache) Has(key []byte) (bool, error)
- func (db *MemoryCache) Len() int
- func (db *MemoryCache) NewIterator() Iterator
- func (db *MemoryCache) NewIteratorWithPrefix(prefix []byte) Iterator
- func (db *MemoryCache) NewIteratorWithStart(start []byte) Iterator
- func (db *MemoryCache) Put(key []byte, value []byte) error
- func (db *MemoryCache) PutExpired(key []byte, value []byte, expired time.Duration) error
- func (db *MemoryCache) Stat(property string) (string, error)
Constants ¶
const ( MemCacheClosedError = iota MemCacheNotFoundError ExpiredError )
Variables ¶
var ErrCodeMessage = map[int]struct { Code int Message string }{ MemCacheClosedError: {-1, "Database closed"}, MemCacheNotFoundError: {-2, "Not found for key"}, ExpiredError: {-3, "expired key time"}, }
Functions ¶
func GetBeaconBestStateCachedKey ¶
func GetBeaconBestStateCachedKey() []byte
func GetBlocksCachedKey ¶
func GetListOutputcoinCachedKey ¶
GetListOutputcoinCachedKey - build key on memcache for list output coin of publickey
func GetListPrivacyTokenCachedKey ¶
func GetListPrivacyTokenCachedKey() []byte
func GetListPrivacyTokenCrossShardCachedKey ¶
func GetListPrivacyTokenCrossShardCachedKey() []byte
func GetShardBestStateCachedKey ¶
func GetShardBestStateCachedKey() []byte
Types ¶
type Iteratee ¶
type Iteratee interface { // NewIterator creates a binary-alphabetical iterator over the entire keyspace // contained within the key-value database. NewIterator() Iterator // NewIteratorWithStart creates a binary-alphabetical iterator over a subset of // database content starting at a particular initial key (or after, if it does // not exist). NewIteratorWithStart(start []byte) Iterator // NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset // of database content with a particular key prefix. NewIteratorWithPrefix(prefix []byte) Iterator }
Iteratee wraps the NewIterator methods of a backing data store.
type Iterator ¶
type Iterator interface { // Next moves the iterator to the next key/value pair. It returns whether the // iterator is exhausted. Next() bool // Error returns any accumulated error. Exhausting all the key/value pairs // is not considered to be an error. Error() error // Key returns the key of the current key/value pair, or nil if done. The caller // should not modify the contents of the returned slice, and its contents may // change on the next call to Next. Key() []byte // Value returns the value of the current key/value pair, or nil if done. The // caller should not modify the contents of the returned slice, and its contents // may change on the next call to Next. Value() []byte // Release releases associated resources. Release should always succeed and can // be called multiple times without causing error. Release() }
Iterator iterates over a database's key/value pairs in ascending key order.
When it encounters an error any seek will return false and will yield no key/ value pairs. The error can be queried by calling the Error method. Calling Release is still necessary.
An iterator must be released after use, but it is not necessary to read an iterator until exhaustion. An iterator is not safe for concurrent use, but it is safe to use multiple iterators concurrently.
type MemCacheError ¶
func NewMemCacheError ¶
func NewMemCacheError(key int, err error) *MemCacheError
func (MemCacheError) Error ¶
func (e MemCacheError) Error() string
type MemoryCache ¶
type MemoryCache struct {
// contains filtered or unexported fields
}
MemoryCache is an ephemeral key-value store. Apart from basic data storage functionality it also supports batch writes and iterating over the keyspace in binary-alphabetical order.
func New ¶
func New() *MemoryCache
New returns a wrapped map with all the required database interface methods implemented.
func NewWithCap ¶
func NewWithCap(size int) *MemoryCache
NewWithCap returns a wrapped map pre-allocated to the provided capcity with all the required database interface methods implemented.
func (*MemoryCache) Close ¶
func (db *MemoryCache) Close() error
Close deallocates the internal map and ensures any consecutive data access op failes with an error.
func (*MemoryCache) Compact ¶
func (db *MemoryCache) Compact(start []byte, limit []byte) error
Compact is not supported on a memory database.
func (*MemoryCache) Delete ¶
func (db *MemoryCache) Delete(key []byte) error
Delete removes the key from the key-value store.
func (*MemoryCache) Get ¶
func (db *MemoryCache) Get(key []byte) ([]byte, error)
Get retrieves the given key if it's present in the key-value store.
func (*MemoryCache) Has ¶
func (db *MemoryCache) Has(key []byte) (bool, error)
Has retrieves if a key is present in the key-value store.
func (*MemoryCache) Len ¶
func (db *MemoryCache) Len() int
Len returns the number of entries currently present in the memory database.
Note, this method is only used for testing (i.e. not public in general) and does not have explicit checks for closed-ness to allow simpler testing code.
func (*MemoryCache) NewIterator ¶
func (db *MemoryCache) NewIterator() Iterator
NewIterator creates a binary-alphabetical iterator over the entire keyspace contained within the memory database.
func (*MemoryCache) NewIteratorWithPrefix ¶
func (db *MemoryCache) NewIteratorWithPrefix(prefix []byte) Iterator
NewIteratorWithPrefix creates a binary-alphabetical iterator over a subset of database content with a particular key prefix.
func (*MemoryCache) NewIteratorWithStart ¶
func (db *MemoryCache) NewIteratorWithStart(start []byte) Iterator
NewIteratorWithStart creates a binary-alphabetical iterator over a subset of database content starting at a particular initial key (or after, if it does not exist).
func (*MemoryCache) Put ¶
func (db *MemoryCache) Put(key []byte, value []byte) error
Put inserts the given value into the key-value store.
func (*MemoryCache) PutExpired ¶
Put inserts the given value into the key-value store. expired is mili second