cache

package
v0.0.0-...-5ef1371 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2021 License: CC0-1.0 Imports: 3 Imported by: 0

README

cache

The provides the cache package wich implements a fixed-size thread safe R+log(C) cache.

Documentation

Overview

This package implements a fixed-size thread safe *R+log(C)* cache.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(decay float64, timer rlogc.Timer, size int, cb EvictCB) *Cache

func (*Cache) Add

func (c *Cache) Add(key, value interface{}) (evicted bool)

Adds or replaces a cache entry.

func (*Cache) Contains

func (c *Cache) Contains(key interface{}) bool

Looks up a cache entry without updating the cache statistics and witout returning it's value.

func (*Cache) ContainsOrAdd

func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool)

func (*Cache) Get

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

Looks up a cache entry.

func (*Cache) GetOldest

func (c *Cache) GetOldest() (key interface{}, value interface{}, ok bool)

func (*Cache) Len

func (c *Cache) Len() int

Returns the number of entries.

func (*Cache) Peek

func (c *Cache) Peek(key interface{}) (value interface{}, ok bool)

Looks up a cache entry without updating the cache statistics.

func (*Cache) PeekOrAdd

func (c *Cache) PeekOrAdd(key, value interface{}) (previous interface{}, ok, evicted bool)

Looks up a cache entry without updating the cache statistics and adds a new entry, if no cache entry was found.

func (*Cache) Remove

func (c *Cache) Remove(key interface{}) (present bool)

Removes a specific cache entry.

func (*Cache) RemoveOldest

func (c *Cache) RemoveOldest() (key interface{}, value interface{}, ok bool)

func (*Cache) Resize

func (c *Cache) Resize(size int) (evicted int)

type EvictCB

type EvictCB func(key, value interface{})

EvictCB is used to get a callback when a cache entry is evicted.

Jump to

Keyboard shortcuts

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