cache

package
v1.1.3 Latest Latest
Warning

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

Go to latest
Published: May 24, 2018 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) uint32

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 uint32, el interface{})

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

func (*Cache) Get

func (c *Cache) Get(key uint32) (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 uint32)

Remove removes the element indexed with key.

Jump to

Keyboard shortcuts

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