cache

package
v0.0.3-openssl Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2026 License: Apache-2.0 Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package cache implements a cache. The cache hold 256 shards, each shard holds a cache: a map with a mutex. There is no fancy expunge algorithm, it just randomly evicts elements when it gets full.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hash

func Hash(what []byte) uint64

Hash returns the FNV hash of what.

Types

type Cache

type Cache[T any] struct {
	// contains filtered or unexported fields
}

Cache is cache.

func New

func New[T any](size int) *Cache[T]

New returns a new cache.

func (*Cache[T]) Add

func (c *Cache[T]) Add(key uint64, el T) bool

Add adds a new element to the cache. If the element already exists it is overwritten. Returns true if an existing element was evicted to make room for this element.

func (*Cache[T]) Get

func (c *Cache[T]) Get(key uint64) (T, bool)

Get looks up element index under key.

func (*Cache[T]) Len

func (c *Cache[T]) Len() int

Len returns the number of elements in the cache.

func (*Cache[T]) Remove

func (c *Cache[T]) Remove(key uint64)

Remove removes the element indexed with key.

func (*Cache[T]) Walk

func (c *Cache[T]) Walk(f func(map[uint64]T, uint64) bool)

Walk walks each shard in the cache.

Jump to

Keyboard shortcuts

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