cache

package
v1.0.43 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get retrieves items from the cache by key.
	// If an item for a particular key is not found, its position in the result will be nil.
	Get(keys ...string) []Item

	// Put adds an item to the cache.
	Put(key string, item Item)

	// Remove clears items with the given keys from the cache
	Remove(keys ...string)

	// Size returns the size of all items currently in the cache.
	Size() uint64
}

Cache is a bounded-size in-memory cache of sized items with a configurable eviction policy

func New

func New(capacity uint64, options ...CacheOption) Cache

New returns a cache with the requested options configured. The cache consumes memory bounded by a fixed capacity, plus tracking overhead linear in the number of items.

type CacheOption

type CacheOption func(*cache)

CacheOption configures a cache.

func EvictionPolicy

func EvictionPolicy(policy Policy) CacheOption

EvictionPolicy sets the eviction policy to be used to make room for new items. If not provided, default is LeastRecentlyUsed.

type Item

type Item interface {
	// Size returns the item's size, in bytes
	Size() uint64
}

Item is an item in a cache

type Policy

type Policy uint8

Policy is a cache eviction policy for use with the EvictionPolicy CacheOption.

const (
	// LeastRecentlyAdded indicates a least-recently-added eviction policy.
	LeastRecentlyAdded Policy = iota
	// LeastRecentlyUsed indicates a least-recently-used eviction policy.
	LeastRecentlyUsed
)

Jump to

Keyboard shortcuts

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