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) LoadStats(stats *Stats)
- func (c *Cache) Reset()
- func (c *Cache) Set(k, v []byte)
- 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 pressure.
Actual memory consumption might be slightly higher than configured size.
func (*Cache) Has ¶
Has() checks whether key k exists in cache.
Has() is slightly cheaper than HasGet() and Get().
func (*Cache) HasGet ¶
HasGet() appends value for key k to dst if pair exists. 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 acquired 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.
type Stats ¶
type Stats struct {
// Number of Get() calls (including Has() but not Iterator.GetNext()).
Gets int64
// Number of Set() calls.
Sets int64
// Number of Get() misses (including Has() but not Iterator.GetNext()).
Misses int64
// Number of Get() hash collisions (including Has() but not Iterator.GetNext()).
Collisions int64
// Number of map re-creations.
Vacuums int64
// Number of chunk allocations.
Allocations int64
// Number of chunk deallocations.
Deallocations int64
// Size of allocated chunks.
Allocated int64
}
Stats represents global stats of Cache.