cache

package
v0.0.0-...-a2846b3 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2016 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

The Tideland Go Library cache package provides a caching for individual lazy loaded values. The retrieval function and the timeout have to be specified.

Index

Constants

View Source
const (
	ErrCannotRetrieve = iota + 1
)

Variables

This section is empty.

Functions

func PackageVersion

func PackageVersion() version.Version

PackageVersion returns the version of the version package.

Types

type CachedValue

type CachedValue interface {
	// Value returns the cached value. If an error occurred
	// during retrieval that will be returned too.
	Value() (v interface{}, err error)

	// Clear clears the cached value so that it will be
	// retrieved again when Value() is called the next time.
	Clear()

	// Remove removes this cached value from the cache.
	Remove()
}

func NewCachedValue

func NewCachedValue(r RetrievalFunc, ttl time.Duration) CachedValue

NewCachedValue creates a new cache. The retrieval func is responsible for the retrieval of the value while ttl defines how long the value is valid.

type RetrievalFunc

type RetrievalFunc func() (interface{}, error)

RetrievalFunc is the signature of a function responsible for the retrieval of the cached value from somewhere else in the system, e.g. a database.

Jump to

Keyboard shortcuts

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