Documentation
¶
Index ¶
- type Cache
- func (c *Cache) Contains(kind cache.EntryKind, hash string) (bool, int64)
- func (c *Cache) Get(kind cache.EntryKind, hash string) (io.ReadCloser, int64, error)
- func (c *Cache) GetValidatedActionResult(hash string) (*pb.ActionResult, []byte, error)
- func (c *Cache) MaxSize() int64
- func (c *Cache) Put(kind cache.EntryKind, hash string, expectedSize int64, r io.Reader) error
- func (c *Cache) Stats() (currentSize int64, numItems int)
- type EvictCallback
- type Key
- type SizedLRU
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 ¶
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
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
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
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.
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