Documentation
¶
Index ¶
- type DiskCacheStore
- func (d *DiskCacheStore) Clean(maxSize int64, maxAge time.Duration) error
- func (d *DiskCacheStore) Dir() string
- func (d *DiskCacheStore) Get(key []byte, name string) ([]byte, error)
- func (d *DiskCacheStore) Has(key []byte) (bool, error)
- func (d *DiskCacheStore) Namespace(prefix string) Store
- func (d *DiskCacheStore) Put(key []byte, name string, value []byte) error
- func (d *DiskCacheStore) Stats() (entries int, totalSize int64, err error)
- type S3CacheStore
- func (s *S3CacheStore) Bucket() string
- func (s *S3CacheStore) Clean(maxSize int64, maxAge time.Duration) error
- func (s *S3CacheStore) Dir() string
- func (s *S3CacheStore) Get(key []byte, name string) ([]byte, error)
- func (s *S3CacheStore) Has(key []byte) (bool, error)
- func (s *S3CacheStore) Namespace(prefix string) Store
- func (s *S3CacheStore) Put(key []byte, name string, value []byte) error
- func (s *S3CacheStore) Stats() (entries int, totalSize int64, err error)
- type S3Options
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DiskCacheStore ¶
type DiskCacheStore struct {
// contains filtered or unexported fields
}
DiskCacheStore is a content-addressable on-disk store. Each key maps to a directory `<dir>/<hh>/<full-hex-key>/` that holds one file per named blob (output, stdout, stderr, exit_code, metadata, ...).
writes is shared across the root and every Namespace-derived store so that concurrent Put calls for the same destination path dedup to a single filesystem write. Callers like the worker's CAS receiver build a fresh Namespace wrapper per request (see internal/worker/cas.go), so a per-struct group would never coordinate — the singleflight.Group must travel with the namespaced clones.
func NewDiskCacheStore ¶
func NewDiskCacheStore(dir string, maxSize string) (*DiskCacheStore, error)
func (*DiskCacheStore) Clean ¶
func (d *DiskCacheStore) Clean(maxSize int64, maxAge time.Duration) error
Clean evicts cache entries to satisfy the given constraints. If maxSize is positive, LRU entries are removed until total size is at or below it. If maxAge is positive, entries whose newest blob is older than maxAge are removed regardless of size. Both constraints can be applied in one call.
func (*DiskCacheStore) Dir ¶
func (d *DiskCacheStore) Dir() string
Dir returns the root directory of this cache store.
func (*DiskCacheStore) Namespace ¶
func (d *DiskCacheStore) Namespace(prefix string) Store
Namespace returns a DiskCacheStore rooted at <d.dir>/<prefix>. maxSize is *not* inherited — namespaced stores default to unlimited so the caller decides whether to budget the namespace separately; otherwise three namespaces sharing one root would each evict to the parent's maxSize and overshoot 3x.
type S3CacheStore ¶
type S3CacheStore struct {
// contains filtered or unexported fields
}
S3CacheStore is a content-addressable S3-backed Store. Safe for concurrent use across goroutines; the eviction state is mutex- protected and only one eviction runs at a time process-wide.
func NewS3CacheStore ¶
func NewS3CacheStore(opts S3Options) (*S3CacheStore, error)
NewS3CacheStore creates an S3-backed cache from opts. See package doc for the on-disk layout and eviction model.
func (*S3CacheStore) Bucket ¶
func (s *S3CacheStore) Bucket() string
func (*S3CacheStore) Clean ¶
func (s *S3CacheStore) Clean(maxSize int64, maxAge time.Duration) error
Clean evicts cache entries to satisfy the given constraints. If maxSize is positive, LRU entries are removed until total size is at or below it. If maxAge is positive, entries whose newest blob is older than maxAge are removed regardless of size.
func (*S3CacheStore) Dir ¶
func (s *S3CacheStore) Dir() string
func (*S3CacheStore) Namespace ¶
func (s *S3CacheStore) Namespace(prefix string) Store
Namespace returns an S3CacheStore view that operates under "<current prefix><prefix>/" — e.g. starting from "cache/" and namespacing to "compile" yields "cache/compile/". maxSize and the in-memory eviction estimate are NOT inherited; the namespaced store gets its own (defaulted to unlimited) so the caller decides whether to budget the namespace separately. The underlying S3 client and per-op timeouts are shared.
type S3Options ¶
type S3Options struct {
Bucket string
Region string
Endpoint string
AccessKey string
SecretKey string
MaxSize int64
AutoCreate bool
// MaxBlobBytes optionally overrides defaultS3MaxBlobBytes.
MaxBlobBytes int64
}
S3Options captures everything NewS3CacheStore needs. Most fields default to sane values when zero — only Bucket is strictly required; supply MaxSize=0 for "unlimited".
type Store ¶
type Store interface {
// Get returns the value stored under (key, name), or nil if no
// such entry exists. A missing entry is not an error.
Get(key []byte, name string) ([]byte, error)
// Put stores value under (key, name). If the cache has a size
// limit, it should evict entries as needed to stay within it.
// Eviction is performed at the key (entry) granularity: all
// named blobs sharing a key are evicted together.
Put(key []byte, name string, value []byte) error
// Has reports whether any blob exists for the given key.
Has(key []byte) (bool, error)
Stats() (entries int, totalSize int64, err error)
Clean(maxSize int64, maxAge time.Duration) error
Dir() string
// Namespace returns a Store view rooted at prefix within this
// store's address space. All Get/Put/Has/Stats/Clean calls on the
// returned store operate only on entries under that prefix; calls
// on the parent see entries from every namespace.
//
// Used to partition one underlying store across multiple cache
// facades — e.g. compile entries under "compile", CAS source
// blobs under "source", manifests under "manifest" — so the same
// disk root or S3 bucket backs all of them without key
// collision. Prefix must be a single path component (no slashes,
// no traversal); implementations validate and may panic on
// invalid input.
Namespace(prefix string) Store
}
Store is a content-addressable store keyed by an opaque (typically hash) byte key. Each key maps to a small set of named blobs, so a single cache entry can hold the compiler artifact alongside its stdout, stderr, exit code, and metadata.
Conventional names used by the compiler cache:
"output" - the compiler output object (e.g. .o) "stdout" - captured stdout "stderr" - captured stderr "exit_code" - exit code as ASCII "metadata" - JSON metadata (timestamp, compiler, command, ...)
func FromConfig ¶
func FromConfig(cfgs []config.CacheConfig) ([]Store, error)
FromConfig builds the configured cache stores from a slice of CacheConfig entries, in the order they appear. Both the client (via runner) and the worker (in paranoid mode) call this so the cache schema lives in exactly one place.