cache

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCacheNotFound error
	ErrCacheNotFound = errors.New("cache not found")
	// ErrCacheExpired error
	ErrCacheExpired = errors.New("cache expired")
)

Functions

func AcquireBuf added in v1.0.0

func AcquireBuf() *bytes.Buffer

AcquireBuf returns a buf from pool

func AcquireHash added in v1.0.0

func AcquireHash() hash.Hash64

AcquireHash returns a hash from pool

func Hash

func Hash(q dns.Question, cd ...bool) uint64

Hash returns a hash for cache

func ReleaseBuf added in v1.0.0

func ReleaseBuf(buf *bytes.Buffer)

ReleaseBuf returns buf to pool

func ReleaseHash added in v1.0.0

func ReleaseHash(h hash.Hash64)

ReleaseHash returns hash to pool

Types

type Cache added in v0.2.4

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

Cache is cache.

func New added in v0.2.4

func New(size int) *Cache

New returns a new cache.

func (*Cache) Add added in v0.2.4

func (c *Cache) Add(key uint64, el any)

Add adds a new element to the cache. If the element already exists it is overwritten.

func (*Cache) Get added in v0.2.4

func (c *Cache) Get(key uint64) (any, bool)

Get looks up element index under key.

func (*Cache) Len added in v0.2.4

func (c *Cache) Len() int

Len returns the number of elements in the cache.

func (*Cache) Remove added in v0.2.4

func (c *Cache) Remove(key uint64)

Remove removes the element indexed with key.

type SyncUInt64Map added in v1.5.0

type SyncUInt64Map[V any] struct {
	// contains filtered or unexported fields
}

SyncUInt64Map: lock-free hash map using CAS operations on linked lists

func NewSyncUInt64Map added in v1.5.0

func NewSyncUInt64Map[V any](sizePower uint) *SyncUInt64Map[V]

NewSyncUInt64Map creates a new optimized map for uint64 keys

func (*SyncUInt64Map[V]) All added in v1.5.0

func (m *SyncUInt64Map[V]) All() iter.Seq2[uint64, V]

func (*SyncUInt64Map[V]) Del added in v1.5.0

func (m *SyncUInt64Map[V]) Del(key uint64) bool

Del removes a key from the map

func (*SyncUInt64Map[V]) ForEach added in v1.5.0

func (m *SyncUInt64Map[V]) ForEach(f func(uint64, V) bool)

ForEach iterates through all key-value pairs

func (*SyncUInt64Map[V]) Get added in v1.5.0

func (m *SyncUInt64Map[V]) Get(key uint64) (V, bool)

Get retrieves a value by key

func (*SyncUInt64Map[V]) Has added in v1.5.0

func (m *SyncUInt64Map[V]) Has(key uint64) bool

Has checks if a key exists in the map without retrieving its value

func (*SyncUInt64Map[V]) Len added in v1.5.0

func (m *SyncUInt64Map[V]) Len() int64

Len returns the number of elements in the map

func (*SyncUInt64Map[V]) RandomSample added in v1.5.0

func (m *SyncUInt64Map[V]) RandomSample(maxSample int) []uint64

RandomSample: O(sample) complexity by sampling random buckets, not full scan

func (*SyncUInt64Map[V]) Set added in v1.5.0

func (m *SyncUInt64Map[V]) Set(key uint64, value V)

Set adds or updates a key-value pair

Jump to

Keyboard shortcuts

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