cache

package
v0.0.0-...-fc8c377 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package cache provides a simple caching mechanism that limits the age of cache entries and tries to avoid large repopulation events by staggering refresh times.

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
}

Cache holds a time-limited set of values for arbitrary keys.

func New

func New(maxAge time.Duration) *Cache

New returns a new Cache that will cache items for at most maxAge.

func (*Cache) Evict

func (c *Cache) Evict(key Key)

Evict removes the entry with the given key from the cache if present.

func (*Cache) EvictAll

func (c *Cache) EvictAll()

EvictAll removes all entries from the cache.

func (*Cache) Get

func (c *Cache) Get(key Key, fetch func() (interface{}, error)) (interface{}, error)

Get returns the value for the given key, using fetch to fetch the value if it is not found in the cache. If fetch returns an error, the returned error from Get will have the same cause.

func (*Cache) Len

func (c *Cache) Len() int

Len returns the total number of cached entries.

type Key

type Key interface{}

Key represents a cache key. It must be a comparable type.

Jump to

Keyboard shortcuts

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