disk

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 18 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v1.1.0

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a filesystem-based LRU cache, with an optional backend proxy.

func New

func New(dir string, maxSizeBytes int64, proxy cache.Proxy) *Cache

New returns a new instance of a filesystem-based cache rooted at `dir`, with a maximum size of `maxSizeBytes` bytes and an optional backend `proxy`. Cache is safe for concurrent use.

func (*Cache) Contains added in v1.1.0

func (c *Cache) Contains(kind cache.EntryKind, hash string) (bool, int64)

Contains returns true if the `hash` key exists in the cache, and the size if known (or -1 if unknown).

If there is a local cache miss, the proxy backend (if there is one) will be checked.

func (*Cache) Get added in v1.1.0

func (c *Cache) Get(kind cache.EntryKind, hash string) (io.ReadCloser, int64, error)

Get returns an io.ReadCloser with the content of the cache item stored under `hash` and the number of bytes that can be read from it. If the item is not found, the io.ReadCloser will be nil. If some error occurred when processing the request, then it is returned.

func (*Cache) GetValidatedActionResult added in v1.1.0

func (c *Cache) GetValidatedActionResult(hash string) (*pb.ActionResult, []byte, error)

GetValidatedActionResult returns a valid ActionResult and its serialized value from the CAS if it and all its dependencies are also available. If not, nil values are returned. If something unexpected went wrong, return an error.

func (*Cache) MaxSize added in v1.1.0

func (c *Cache) MaxSize() int64

MaxSize returns the maximum cache size in bytes.

func (*Cache) Put added in v1.1.0

func (c *Cache) Put(kind cache.EntryKind, hash string, expectedSize int64, r io.Reader) error

Put stores a stream of `expectedSize` bytes from `r` into the cache. If `hash` is not the empty string, and the contents don't match it, a non-nil error is returned.

func (*Cache) Stats added in v1.1.0

func (c *Cache) Stats() (currentSize int64, numItems int)

Stats returns the current size of the cache in bytes, and the number of items stored in the cache.

type EvictCallback

type EvictCallback func(key Key, value sizedItem)

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

type Key

type Key interface{}

Key is the type used for identifying cache items. For non-test code, this is a string of the form "<keyspace>/<hash>". Some test code uses ints for simplicity.

TODO: update the test code to use strings too, then drop all the type assertions.

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