Documentation ¶
Index ¶
- Constants
- type Cache
- type CacheConfig
- type EvictCallback
- type Key
- type Option
- func WithAccessLogger(logger *log.Logger) Option
- func WithEndpointMetrics() Option
- func WithMaxBlobSize(size int64) Option
- func WithProxyBackend(proxy cache.Proxy) Option
- func WithProxyMaxBlobSize(maxProxyBlobSize int64) Option
- func WithStorageMode(mode string) Option
- func WithZstdImplementation(impl string) Option
- 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) RegisterMetrics()
- 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) UncompressedSize() int64
- func (c *SizedLRU) Unreserve(size int64) error
Constants ¶
const BlockSize = 4096
Actual disk usage will be estimated by rounding file sizes up to the nearest multiple of this number.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface { Get(ctx context.Context, kind cache.EntryKind, hash string, size int64, offset int64) (io.ReadCloser, int64, error) GetValidatedActionResult(ctx context.Context, hash string) (*pb.ActionResult, []byte, error) GetZstd(ctx context.Context, hash string, size int64, offset int64) (io.ReadCloser, int64, error) Put(ctx context.Context, kind cache.EntryKind, hash string, size int64, r io.Reader) error Contains(ctx context.Context, kind cache.EntryKind, hash string, size int64) (bool, int64) FindMissingCasBlobs(ctx context.Context, blobs []*pb.Digest) ([]*pb.Digest, error) MaxSize() int64 Stats() (totalSize int64, reservedSize int64, numItems int, uncompressedSize int64) RegisterMetrics() }
type CacheConfig ¶
type CacheConfig struct {
// contains filtered or unexported fields
}
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 Option ¶
type Option func(*CacheConfig) error
func WithAccessLogger ¶
func WithEndpointMetrics ¶
func WithEndpointMetrics() Option
func WithMaxBlobSize ¶
func WithProxyBackend ¶
func WithProxyMaxBlobSize ¶
func WithStorageMode ¶
func WithZstdImplementation ¶
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, initialCapacity int) 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 if the item cannot be added to the cache because too much space is reserved.
Note that this function rounds file sizes up to the nearest BlockSize (4096) bytes, as an estimate of actual disk usage since most linux filesystems default to 4kb blocks.
func (*SizedLRU) RegisterMetrics ¶
func (c *SizedLRU) RegisterMetrics()