disk

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2021 License: Apache-2.0 Imports: 23 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, error)

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, size int64) (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.

Callers should provide the `size` of the item, or -1 if unknown.

func (*Cache) Get added in v1.1.0

func (c *Cache) Get(kind cache.EntryKind, hash string, size int64) (rc io.ReadCloser, s int64, rErr 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. Callers should provide the `size` of the item to be retrieved, or -1 if unknown.

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, size int64, r io.Reader) (rErr error)

Put stores a stream of `size` 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() (totalSize int64, reservedSize 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 lruItem)

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 struct {
	// contains filtered or unexported fields
}

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

func (*SizedLRU) Add

func (c *SizedLRU) Add(key Key, value lruItem) (ok bool)

Add adds a (key, value) to the cache, evicting items as necessary. Add returns false ( and does not add the item) if the item size is larger than the maximum size of the cache, or it cannot be added to the cache because too much space is reserved.

func (*SizedLRU) Get

func (c *SizedLRU) Get(key Key) (value lruItem, ok bool)

Get looks up a key in the cache

func (*SizedLRU) Len

func (c *SizedLRU) Len() int

Len returns the number of items in the cache

func (*SizedLRU) MaxSize

func (c *SizedLRU) MaxSize() int64

func (*SizedLRU) Remove

func (c *SizedLRU) Remove(key Key)

Remove removes a (key, value) from the cache

func (*SizedLRU) Reserve added in v1.3.0

func (c *SizedLRU) Reserve(size int64) (bool, error)

func (*SizedLRU) ReservedSize added in v1.3.0

func (c *SizedLRU) ReservedSize() int64

func (*SizedLRU) TotalSize added in v1.3.0

func (c *SizedLRU) TotalSize() int64

func (*SizedLRU) Unreserve added in v1.3.0

func (c *SizedLRU) Unreserve(size int64) error

Jump to

Keyboard shortcuts

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