cache

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleanuper

type Cleanuper interface {
	Cleanup()
}

type LruCache

type LruCache struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LruCache is a kind of LRU cache. Objects that are too old are removed, and if the cache is full, the oldest item(s) will be removed. When an item is set more than once, it is pushed to the end so its last to be removed. Limits are approximate, as garbage collecting will randomly happen. Also, in order to prevent memory thrashing, strict order is not preserved, but items will fall out more or less in LRU order. Someday we may offer a backing store version to extend the size of the cache to disk or some other kind of storage If the item has a "Removed" function, that function will be called when the item falls out of the cache. If the item has a "Cleanup" function, that function will be called when the item is removed from memory. If the cache has a backing store, it may be removed from memory, but still in the disk-based cache.

func NewLruCache

func NewLruCache(maxItemCount int, ttl int64) *LruCache

Create and return a new cache. maxItemCount is the maximum number of items the cache can hold ttl is the age in seconds past when items will be removed

func (*LruCache) Get

func (o *LruCache) Get(key string) interface{}

Get returns the item based on its id. If not found, it will return nil.

func (*LruCache) Has

func (o *LruCache) Has(key string) (exists bool)

Has tests for the existence of the key

func (*LruCache) Set

func (o *LruCache) Set(key string, v interface{})

Puts the item into the cache, and updates its access time, pushing it to the end of the removal queue

type Remover

type Remover interface {
	Removed()
}

Jump to

Keyboard shortcuts

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