Documentation ¶
Index ¶
- type Cache
- func (c *Cache) Contains(kind cache.EntryKind, hash string, size int64) (bool, int64)
- func (c *Cache) Get(kind cache.EntryKind, hash string, size int64) (rc io.ReadCloser, s int64, rErr 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, size int64, r io.Reader) (rErr error)
- func (c *Cache) Stats() (totalSize int64, reservedSize int64, numItems int)
- type EvictCallback
- type Key
- type SizedLRU
- func (c *SizedLRU) Add(key Key, value lruItem) (ok bool)
- func (c *SizedLRU) Get(key Key) (value lruItem, ok bool)
- func (c *SizedLRU) Len() int
- func (c *SizedLRU) MaxSize() int64
- func (c *SizedLRU) Remove(key Key)
- func (c *SizedLRU) Reserve(size int64) (bool, error)
- func (c *SizedLRU) ReservedSize() int64
- func (c *SizedLRU) TotalSize() int64
- func (c *SizedLRU) Unreserve(size int64) error
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.
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
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 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 ¶
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.