Version: v1.10.0 Latest Latest

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 2 Imported by: 154



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.



This section is empty.


This section is empty.


func Hash

func Hash(what []byte) uint64

Hash returns the FNV hash of what.


type Cache

type Cache struct {
	// contains filtered or unexported fields

Cache is cache.

func New

func New(size int) *Cache

New returns a new cache.

func (*Cache) Add

func (c *Cache) Add(key uint64, el interface{}) 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) Get

func (c *Cache) Get(key uint64) (interface{}, bool)

Get looks up element index under key.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the number of elements in the cache.

func (*Cache) Remove

func (c *Cache) Remove(key uint64)

Remove removes the element indexed with key.

func (*Cache) Walk added in v1.8.4

func (c *Cache) Walk(f func(map[uint64]interface{}, uint64) bool)

Walk walks each shard in the cache.

Source Files

Jump to

Keyboard shortcuts

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