kv

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

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 New

func New(size int) *Cache

New() creates a new Cache instance.

size

func (*Cache) Del

func (c *Cache) Del(k []byte)

Del() deletes KV pair from cache with key k.

func (*Cache) Get

func (c *Cache) Get(dst, k []byte) (res []byte)

Get() appends value for key k to dst. Returns nil if not found.

func (*Cache) Has

func (c *Cache) Has(k []byte) (found bool)

Has() checks whether key k exists in cache.

Has() is slightly cheaper than HasGet() and Get().

func (*Cache) HasGet

func (c *Cache) HasGet(dst, k []byte) (res []byte, found bool)

HasGet() appends value for key k to dst if pair exists. Returns nil, false if not found.

HasGet() is equal to Get() in performance.

func (*Cache) Iterator

func (c *Cache) Iterator() *Iterator

Iterator() creates a new Iterator instance.

func (*Cache) LoadStats added in v0.2.0

func (c *Cache) LoadStats(stats *Stats)

LoadStats() acquires global stats of Cache.

func (*Cache) Reset

func (c *Cache) Reset()

Reset removes all KV pairs from cache

func (*Cache) Set

func (c *Cache) Set(k, v []byte)

Set() sets k, v into the cache. KV pairs with total length exceeding (64KB - 4B) are silently dropped.

k and v are safe to be modified after Set() returns

type Iterator

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

func (*Iterator) GetNext

func (it *Iterator) GetNext(kDst, vDst []byte) ([]byte, []byte, bool)

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.

Directories

Path Synopsis
utils
bench command
LLM usage: the bench utility is generated with deepseek-v4-pro.
LLM usage: the bench utility is generated with deepseek-v4-pro.

Jump to

Keyboard shortcuts

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