cache

package
v0.0.0-...-36c2227 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

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 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

func (c *Cache) Walk(f func(map[uint64]interface{}, 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