cache

package
v0.0.0-...-a0a3655 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package cache implements both in-memory and on-disk caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	io.Closer

	// Keys returns the list of all cached digests in LRU order.
	Keys() isolated.HexDigests

	// Touch updates the LRU position of an item to ensure it is kept in the
	// cache.
	//
	// Returns true if item is in cache.
	Touch(digest isolated.HexDigest) bool

	// Evict removes item from cache if it's there.
	Evict(digest isolated.HexDigest)

	// Add reads data from src and stores it in cache.
	Add(digest isolated.HexDigest, src io.Reader) error

	// Read returns contents of the cached item.
	Read(digest isolated.HexDigest) (io.ReadCloser, error)

	// Hardlink ensures file at |dest| has the same content as cached |digest|.
	//
	// Note that the behavior when dest already exists is undefined. It will work
	// on all POSIX and may or may not fail on Windows depending on the
	// implementation used. Do not rely on this behavior.
	Hardlink(digest isolated.HexDigest, dest string, perm os.FileMode) error

	// GetAdded returns a list of file size added to cache.
	GetAdded() []int64

	// GetAdded returns a list of file size used from cache.
	GetUsed() []int64
}

Cache is a cache of objects.

All implementations must be thread-safe.

func NewDisk

func NewDisk(policies Policies, path, namespace string) (Cache, error)

NewDisk creates a disk based cache.

It may return both a valid Cache and an error if it failed to load the previous cache metadata. It is safe to ignore this error.

func NewMemory

func NewMemory(policies Policies, namespace string) Cache

NewMemory creates a purely in-memory cache.

type Policies

type Policies struct {
	// MaxSize trims if the cache gets larger than this value. If 0, the cache is
	// effectively a leak.
	MaxSize units.Size
	// MaxItems is the maximum number of items to keep in the cache. If 0, do not
	// enforce a limit.
	MaxItems int
	// MinFreeSpace trims if disk free space becomes lower than this value. If 0,
	// it unconditionally fills the disk. Only makes sense when using disk based
	// cache.
	//
	// BUG: Implement Policies.MinFreeSpace.
	MinFreeSpace units.Size
}

Policies is the policies to use on a cache to limit it's footprint.

It's a cache, not a leak.

Jump to

Keyboard shortcuts

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