cache

package
v0.0.0-...-6064d3c Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTooBig is returned by Cache::Put when when the item size is bigger than the
	// cache size limit.
	ErrTooBig = errors.New("item bigger than the cache size limit")
)

Functions

func NewFsCache

func NewFsCache(dir string, maxSizeBytes int64) *fsCache

NewFsCache returns a new instance of a filesystem-based cache rooted at `dir`, with a maximum size of `maxSizeBytes` bytes.

Types

type Cache

type Cache interface {
	// Put stores a stream of `size` bytes from `r` into the cache. If `expectedSha256` is
	// not the empty string, and the contents don't match it, an error is returned
	Put(key string, size int64, expectedSha256 string, r io.Reader) error
	// Get writes the content of the cache item stored under `key` to `w`. If the item is
	// not found, it returns ok = false.
	Get(key string, w http.ResponseWriter) (ok bool, err error)
	Contains(key string) (ok bool, err error)

	// Stats
	MaxSize() int64
	CurrentSize() int64
	NumItems() int
}

Cache is the interface for a generic blob storage backend. Implementers should handle locking internally.

type EvictCallback

type EvictCallback func(key Key, value SizedItem)

EvictCallback is the type of callbacks that are invoked when items are evicted.

type HTTPCache

type HTTPCache interface {
	CacheHandler(w http.ResponseWriter, r *http.Request)
	StatusPageHandler(w http.ResponseWriter, r *http.Request)
}

HTTPCache ...

func NewHTTPCache

func NewHTTPCache(cacheDir string, maxBytes int64, accessLogger logger, errorLogger logger) HTTPCache

NewHTTPCache returns a new instance of the cache. accessLogger will print one line for each HTTP request to the cache. errorLogger will print unexpected server errors. Inexistent files and malformed URLs will not be reported.

type Key

type Key interface{}

type SizedItem

type SizedItem interface {
	Size() int64
}

type SizedLRU

type SizedLRU interface {
	Add(key Key, value SizedItem) (ok bool)
	Get(key Key) (value SizedItem, ok bool)
	Remove(key Key)
	Len() int
	CurrentSize() int64
	MaxSize() int64
}

SizedLRU is an LRU cache that will keep its total size below maxSize by evicting items. SizedLRU is not thread-safe.

func NewSizedLRU

func NewSizedLRU(maxSize int64, onEvict EvictCallback) SizedLRU

NewSizedLRU returns a new sizedLRU cache

Jump to

Keyboard shortcuts

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