memcache

package
v0.0.0-...-7ece11e Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2023 License: MIT Imports: 10 Imported by: 1

README

#Memory caching

A small database on memory to stora key-value data. Support:

  • Put
  • Put by expired time
  • Get
  • Delete
  • Has

Documentation

Overview

Package memorydb implements the key-value database layer based on memory maps. Reference go-etherium memorydb

Index

Constants

View Source
const (
	MemCacheClosedError = iota
	MemCacheNotFoundError
	ExpiredError
)

Variables

View Source
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 GetBlocksCachedKey(shardID int, numBlock int) []byte

func GetListOutputcoinCachedKey

func GetListOutputcoinCachedKey(publicKey []byte, tokenID *common.Hash, shardID byte) []byte

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

type MemCacheError struct {
	Code    int
	Message string
	// contains filtered or unexported fields
}

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

func (db *MemoryCache) PutExpired(key []byte, value []byte, expired time.Duration) error

Put inserts the given value into the key-value store. expired is mili second

func (*MemoryCache) Stat

func (db *MemoryCache) Stat(property string) (string, error)

Stat returns a particular internal stat of the database.

Jump to

Keyboard shortcuts

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