Documentation
¶
Index ¶
Constants ¶
View Source
const ( GO MemoryType = 1 SHM = 2 MMAP = 3 )
View Source
const ( KB = 1024 MB = 1024 * KB GB = 1024 * MB )
Variables ¶
View Source
var ( ErrNoSpace = errors.New("memory no space") ErrMemorySizeTooSmall = errors.New("memory size too small") ErrNotFound = errors.New("key not found") ErrIndexOutOfRange = errors.New("index out of range") ErrFreeListIsEmpty = errors.New("free list is empty") ErrLRUListIsEmpty = errors.New("lru list is empty") ErrCacheClosed = errors.New("cache closed") ErrCloseTimeout = errors.New("cache close timeout") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Has check if the key exists in the cache.
Has(key []byte) bool
// HasWithCounter check if the key exists in the cache and return with counter
HasWithCounter(key []byte) (uint8, bool)
// GetWithCounter get key in the cache and return with counter
GetWithCounter(key []byte) ([]byte, uint8, error)
// GetBufferWithCounter get key with buffer and return with counter
GetBufferWithCounter(key []byte, buffer io.Writer) (uint8, error)
// Get value for the key, it returns ErrNotFound when key not exists
// and LRU move to front
Get(key []byte) ([]byte, error)
// GetWithBuffer write value into buffer, it returns ErrNotFound when key not exists
// and LRU move to front
GetWithBuffer(key []byte, buffer io.Writer) error
// Set key and value
Set(key []byte, value []byte) error
// Peek value for key, but it will not move LRU
Peek(key []byte) ([]byte, error)
// PeekWithBuffer write value into buffer, but it will not move LRU
PeekWithBuffer(key []byte, buffer io.Writer) error
// Delete value for key
Delete(key []byte) error
// Sync flushes all dirty MMAP pages to disk. For non-MMAP memory types, this is a no-op.
Sync() error
// Close the cache wait for the ongoing operations to complete, and return ErrCloseTimeout if timeout.
// For MMAP caches, this also syncs dirty pages to disk before returning.
Close() error
}
type Config ¶
type Config struct {
// memory type in GO SHM MMAP
MemoryType MemoryType
// shard memory key
MemoryKey string
// 支持存储的最大数量, 超过将会触发LRU
MaxElementLen uint64
// 大数据块的最大数量, 超过这个数量将会触发淘汰, 并且这个数值将会用来初始化大数据块的定长Hashmap
MaxBigDataLen uint64
// 定义多少字节为大数据块
BigDataSize uint32
// 当每个分片中的空闲内存不足时会去总内存申请, 分片每次申请内存大小
ShardPerAllocSize uint64
// 分片数量
Shards uint32
// hash算法
Hasher HashFunc `json:"-"`
}
func DefaultConfig ¶
func DefaultConfig() *Config
type Memory ¶
type Memory interface {
// Attach attach memory
Attach() error
// Detach detach memory
Detach() error
// Ptr first ptr
Ptr() unsafe.Pointer
// Size memory total size
Size() uint64
// PtrOffset offset Get ptr
PtrOffset(offset uint64) unsafe.Pointer
// Travel memory
Travel(skipOffset uint64, fn func(ptr unsafe.Pointer, size uint64) uint64)
}
Memory 内存块抽象
type MemoryType ¶
type MemoryType int
type StringKeyCache ¶
type StringKeyCache interface {
Cache
GetStringKey(key string) ([]byte, error)
GetStringKeyWithBuffer(key string, buffer io.Writer) error
SetStringKey(key string, value []byte) error
PeekStringKey(key string) ([]byte, error)
PeekStringKeyWithBuffer(key string, buffer io.Writer) error
DeleteStringKey(key string) error
}
Click to show internal directories.
Click to hide internal directories.