cache

package
v0.0.0-...-8b03266 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCacheWrapToDBHandle

func NewCacheWrapToDBHandle(c Cache, innerDb protocol.DBHandle, l protocol.Logger) protocol.DBHandle

return a cacheWrapToDB which cache , db and log

func QuickSort

func QuickSort(arr []uint64) []uint64
func (c *storeCache) len() int {
	return c.table.Size()
}

快排,获得从小到大排序后的结果,返回

Types

type Cache

type Cache interface {
	// get key from cache or db
	Get(key string) ([]byte, error)
	// set k/v
	Set(key string, entry []byte) error
	// del k
	Delete(key string) error
	// set cache to initial state
	Reset() error
	// close cache
	Close() error
}

type CacheWrapToDBHandle

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

func (*CacheWrapToDBHandle) Close

func (c *CacheWrapToDBHandle) Close() error

close cache and db

func (*CacheWrapToDBHandle) CompactRange

func (c *CacheWrapToDBHandle) CompactRange(start, limit []byte) error

compacts the underlying DB for the given key range

func (*CacheWrapToDBHandle) Delete

func (c *CacheWrapToDBHandle) Delete(key []byte) error

delete key/value from cache and db

func (*CacheWrapToDBHandle) Get

func (c *CacheWrapToDBHandle) Get(key []byte) ([]byte, error)

get value by key from cache and db

func (*CacheWrapToDBHandle) GetDbType

func (c *CacheWrapToDBHandle) GetDbType() string

get db type from db

func (*CacheWrapToDBHandle) GetWriteBatchSize

func (c *CacheWrapToDBHandle) GetWriteBatchSize() uint64

func (*CacheWrapToDBHandle) Has

func (c *CacheWrapToDBHandle) Has(key []byte) (bool, error)

check key whether exist in cache and db

func (*CacheWrapToDBHandle) NewIteratorWithPrefix

func (c *CacheWrapToDBHandle) NewIteratorWithPrefix(prefix []byte) (protocol.Iterator, error)

returns an iterator that contains all the key-values with given prefix

func (*CacheWrapToDBHandle) NewIteratorWithRange

func (c *CacheWrapToDBHandle) NewIteratorWithRange(start []byte, limit []byte) (protocol.Iterator, error)

return iterator from db that contains all the key-values between given key ranges start is included in the results and limit is excluded.

func (*CacheWrapToDBHandle) Put

func (c *CacheWrapToDBHandle) Put(key []byte, value []byte) error

set key/value include cache and db

func (*CacheWrapToDBHandle) WriteBatch

func (c *CacheWrapToDBHandle) WriteBatch(batch protocol.StoreBatcher, sync bool) error

write a batch to cache and db

type StoreCacheMgr

type StoreCacheMgr struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

StoreCacheMgr provide handle to cache instances

func NewStoreCacheMgr

func NewStoreCacheMgr(chainId string, blockWriteBufferSize int, logger protocol.Logger) *StoreCacheMgr

NewStoreCacheMgr construct a new `StoreCacheMgr` with given chainId

func (*StoreCacheMgr) AddBlock

func (mgr *StoreCacheMgr) AddBlock(blockHeight uint64, updateBatch protocol.StoreBatcher)

AddBlock cache a block with given block height and update batch

func (*StoreCacheMgr) Clear

func (mgr *StoreCacheMgr) Clear()

清除缓存,目前未做任何清除操作

func (*StoreCacheMgr) DelBlock

func (mgr *StoreCacheMgr) DelBlock(blockHeight uint64)

DelBlock delete block for the given block height

func (*StoreCacheMgr) Get

func (mgr *StoreCacheMgr) Get(key string) ([]byte, bool)

Get returns value if the key in cache, or returns nil if none exists.

func (*StoreCacheMgr) GetBatch

func (mgr *StoreCacheMgr) GetBatch(height uint64) (protocol.StoreBatcher, error)

根据块高,返回 块对应的cache

func (*StoreCacheMgr) Has

func (mgr *StoreCacheMgr) Has(key string) (bool, bool)

Has returns true if the key in cache, or returns false if none exists. return isDelete,isExist 如果这个key 对应value 是 nil,说明这个key被删除了 所以查找到第一个key,要判断 这个key 是否是被删除的

func (*StoreCacheMgr) KVRange

func (mgr *StoreCacheMgr) KVRange(startKey []byte, endKey []byte) (map[string][]byte, error)

get data from mgr , [startKey,endKey)

func (*StoreCacheMgr) LockForFlush

func (mgr *StoreCacheMgr) LockForFlush()

LockForFlush used to lock cache until all cache item be flushed to db

func (*StoreCacheMgr) UnLockFlush

func (mgr *StoreCacheMgr) UnLockFlush()

UnLockFlush used to unlock cache by release all semaphore

Jump to

Keyboard shortcuts

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