Documentation
¶
Index ¶
- type Cache
- func (c *Cache) Del(k []byte)
- func (c *Cache) Get(dst, k []byte) (res []byte)
- func (c *Cache) Has(k []byte) (found bool)
- func (c *Cache) HasGet(dst, k []byte) (res []byte, found bool)
- func (c *Cache) Iterator() *Iterator
- func (c *Cache) Reset()
- func (c *Cache) Set(k, v []byte)
- func (c *Cache) Stats() Stats
- type Iterator
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thread-safe, memory KV cache.
Cache supports a hard memory cap and auto memory deallocation under low pressue.
Note that actual memory consumption might be higher than configured cap.
func New ¶
New() creates a new Cache instance.
Number of shards = (size + 64K - 1) / 64K.
High lock contention might occur if size is too small. It's advised to use at least NumCPU number of shards.
An acceptable size is 32MB (512 shards).
func (*Cache) Get ¶
Get() copies value for key k into dst[:len(value)]. A new slice will be allocated if dst is nil or not long enough. Returns nil if not found.
func (*Cache) Has ¶
Has() checks whether key k exists in cache.
Has() is slightly cheaper than HasGet() and Get().
func (*Cache) HasGet ¶
HasGet() copies value for key k into dst[:len(value)] if pair exists. A new slice will be allocated if dst is nil or not long enough. Returns nil, false if not found.
HasGet() is equal to Get() in performance.
type Iterator ¶
type Iterator struct {
// contains filtered or unexported fields
}
func (*Iterator) GetNext ¶
GetNext() copies key and value of next KV pair into kDst[:len(key)] and vDst[:len(value)] if next pair exists. New slices will be allocated if is nil or not long enough. Returns nil, nil, false when there are no more pairs.
Pairs acuqired by one Iterator are not guaranteed to be consistent in time. Iteration could pick up pairs inserted after creation of Iterator.
GetNext() does not increment the Gets stat.