Package cache

import "github.com/byte-mug/golang-rlogc/cache"

Overview

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

Index

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.

Dependencies