cache

package
v0.0.0-...-d11f727 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

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 with a customizable eviction policy.

func New

func New(size int) *Cache

New returns a new cache.

func (*Cache) Add

func (c *Cache) Add(key string, el interface{}) error

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

func (*Cache) Get

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

Get looks up element index under key.

func (*Cache) Len

func (c *Cache) Len() int

Len returns an estimate number of elements in the cache. This is an estimate, because each shard is locked one at a time, and items can be added/removed from other shards as each shard is counted.

func (*Cache) Remove

func (c *Cache) Remove(key string)

Remove removes the element indexed with key.

func (*Cache) SetEvict

func (c *Cache) SetEvict(e EvictFn)

func (*Cache) UpdateAdd

func (c *Cache) UpdateAdd(key string, update func(interface{}) interface{}, add func() interface{}) interface{}

type EvictFn

type EvictFn func(interface{}) bool

Jump to

Keyboard shortcuts

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