localcache

package
v0.1.23-oss Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CacheVersion  = "0.0.5"
	CacheLockFile = "cache.lock"
	VersionFile   = "version"

	TreeMetaTag = "tree"
)
View Source
const (
	BlobPrefix   = "blobs/"
	ObjectPrefix = "objects/"
	MapPrefix    = "map/"
)

Variables

View Source
var ErrHashMismatch = errors.New("content hash did not match provided hash")
View Source
var ErrIncompatibleExisting = errors.New("existing cache is not compatible with current version")

Functions

func InitLocalCache

func InitLocalCache(dir string) error

func WriteCacheVersion

func WriteCacheVersion(dir, ver string) error

func WriteCacheVersionIfNotPresent

func WriteCacheVersionIfNotPresent(dir string) error

Types

type CacheOpt

type CacheOpt interface{}

func BypassCompatCheckOpt

func BypassCompatCheckOpt() CacheOpt

func CompressOpt

func CompressOpt(c Compressor) CacheOpt

CompressOpt also stores blob sizes in an xattr since the size can't be obtained from stat

func CreateIfNotExistOpt

func CreateIfNotExistOpt() CacheOpt

func ExclusiveLockOpt

func ExclusiveLockOpt() CacheOpt

func FsyncOpt

func FsyncOpt(fsync bool) CacheOpt

func LevelsOpt

func LevelsOpt(levels int) CacheOpt

func LogRefStoreOpt

func LogRefStoreOpt() CacheOpt

func MapStoreOpt

func MapStoreOpt() CacheOpt

func NoObjectCompressionOpt

func NoObjectCompressionOpt() CacheOpt

func NotifyPutBlobOpt

func NotifyPutBlobOpt(f NotifyFunc) CacheOpt

func NotifyReadOpt

func NotifyReadOpt(f NotifyFunc) CacheOpt

func NotifyWriteOpt

func NotifyWriteOpt(f NotifyFunc) CacheOpt

func PlainEmptyObjectsOpt

func PlainEmptyObjectsOpt() CacheOpt

func ValidateGitHashOpt

func ValidateGitHashOpt() CacheOpt

type CompressMode

type CompressMode bool
const (
	Compressed   CompressMode = true
	Uncompressed CompressMode = false
)

type Compressor

type Compressor interface {
	Compress([]byte) ([]byte, error)
	Decompress([]byte) ([]byte, error)
	NewReader(r io.Reader) io.ReadCloser
}

type Folder

type Folder struct {
	// contains filtered or unexported fields
}

func NewFolder

func NewFolder() *Folder

func (*Folder) Add

func (f *Folder) Add(p string, hash entities.Hash) error

func (*Folder) Get

func (f *Folder) Get(p string) entities.Hash

func (*Folder) GetChildren

func (f *Folder) GetChildren(p string) map[string]entities.Hash

type LocalCache

type LocalCache struct {
	// contains filtered or unexported fields
}

func NewCache

func NewCache(dir string, opts ...CacheOpt) (*LocalCache, error)

func (*LocalCache) AddMapResult

func (c *LocalCache) AddMapResult(ctx context.Context, from entities.Hash, to entities.Hash) error

AddMapResult implements entities.MapStore

func (*LocalCache) Close

func (c *LocalCache) Close() error

func (*LocalCache) CompatibleExistingCache

func (c *LocalCache) CompatibleExistingCache() bool

func (*LocalCache) GetObject

func (c *LocalCache) GetObject(ctx context.Context, key entities.Hash) ([]byte, error)

Get implements entities.ObjectStore

func (*LocalCache) GetRefs

func (c *LocalCache) GetRefs(server string, project string, refs []string) ([]entities.Hash, error)

GetRefs implements entities.CASStore.

func (*LocalCache) GetTempDir

func (c *LocalCache) GetTempDir() string

func (*LocalCache) GetTree

func (c *LocalCache) GetTree(ctx context.Context, key entities.Hash) ([]byte, entities.TreeMeta, error)

func (*LocalCache) HasARI

func (c *LocalCache) HasARI(ctx context.Context, key entities.Hash) (bool, error)

func (*LocalCache) HasBlob

func (c *LocalCache) HasBlob(ctx context.Context, key entities.Hash) (bool, error)

func (*LocalCache) HasCASBlob

func (c *LocalCache) HasCASBlob(ctx context.Context, sha256Hex string) (bool, error)

HasCASBlob checks if a CAS blob is already stored locally on disk under the blobs/ directory (e.g. blobs/<sha256[:3]>/<sha256[3:]>) using its 64-character SHA-256 hex string. This fast disk probe avoids redundant network fetch roundtrips to RBE.

func (*LocalCache) HasObject

func (c *LocalCache) HasObject(ctx context.Context, key entities.Hash) (bool, error)

func (*LocalCache) Lock

func (c *LocalCache) Lock() error

func (*LocalCache) MapResults

func (c *LocalCache) MapResults(ctx context.Context, id entities.Hash) ([]entities.Hash, error)

MapResults implements entities.MapStore

func (*LocalCache) MetaPath

func (c *LocalCache) MetaPath(ctx context.Context, key entities.Hash, meta string) string

func (*LocalCache) MetaSize

func (c *LocalCache) MetaSize(ctx context.Context, treeHash entities.Hash) (int64, error)

func (*LocalCache) ObjectHeader

func (c *LocalCache) ObjectHeader(ctx context.Context, objectHash entities.Hash) (entities.ObjectHeader, error)

func (*LocalCache) OpenARI

func (c *LocalCache) OpenARI(ctx context.Context, key entities.Hash) (io.ReadCloser, error)

func (*LocalCache) OpenBlob

func (c *LocalCache) OpenBlob(ctx context.Context, key entities.Hash) (io.ReadCloser, error)

OpenBlob implements entities.BlobStore

func (*LocalCache) OpenObjectFile

func (c *LocalCache) OpenObjectFile(ctx context.Context, key entities.Hash) (io.ReadCloser, error)

OpenObjectFile implements entities.Object

func (*LocalCache) PutObject

func (c *LocalCache) PutObject(ctx context.Context, key entities.Hash, content []byte) error

Put implements entities.ObjectStore

func (*LocalCache) PutRefs

func (c *LocalCache) PutRefs(server string, project string, refs []entities.RefHash) error

PutRefs implements entities.CASStore.

func (*LocalCache) PutTree

func (c *LocalCache) PutTree(ctx context.Context, key entities.Hash, content []byte, meta entities.TreeMeta) error

func (*LocalCache) RLock

func (c *LocalCache) RLock() error

func (*LocalCache) ReadExistingCacheVersion

func (c *LocalCache) ReadExistingCacheVersion() string

func (*LocalCache) RefreshMapResults

func (c *LocalCache) RefreshMapResults(ctx context.Context, id entities.Hash) error

func (*LocalCache) RemoveARI

func (c *LocalCache) RemoveARI(ctx context.Context, key entities.Hash) error

func (*LocalCache) RemoveBlob

func (c *LocalCache) RemoveBlob(ctx context.Context, key entities.Hash) error

func (*LocalCache) RemoveMeta

func (c *LocalCache) RemoveMeta(ctx context.Context, key entities.Hash, meta string) error

func (*LocalCache) RemoveObject

func (c *LocalCache) RemoveObject(ctx context.Context, key entities.Hash) error

func (*LocalCache) SearchRefs

func (c *LocalCache) SearchRefs(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)

SearchRefs implements entities.CASStore.

func (*LocalCache) Stat

func (c *LocalCache) Stat(ctx context.Context, hash entities.Hash) (entities.StatInfo, error)

func (*LocalCache) Unlock

func (c *LocalCache) Unlock() error

func (*LocalCache) WriteARI

func (c *LocalCache) WriteARI(ctx context.Context, key entities.Hash, reader io.Reader) error

func (*LocalCache) WriteBlob

func (c *LocalCache) WriteBlob(ctx context.Context, key entities.Hash, reader io.Reader) error

Write implements entities.BlobStore

func (*LocalCache) WriteCASBlob

func (c *LocalCache) WriteCASBlob(ctx context.Context, sha256Hex string, reader io.Reader) error

WriteCASBlob streams and writes a CAS blob directly under the local cache's blobs/ directory using its native SHA-256 hex string (e.g. blobs/<sha256[:3]>/<sha256[3:]>). Storing CAS blobs under this layout lets other consumers (e.g. FUSE passthrough) read them directly, eliminating the need for synthetic SHA-1 derivation, BadgerDB identity-store translation, or dual-key disk probing.

func (*LocalCache) WriteObject

func (c *LocalCache) WriteObject(ctx context.Context, key entities.Hash, reader io.Reader) error

Write implements entities.ObjectStore

type LocalStore

type LocalStore struct {
	// contains filtered or unexported fields
}

func NewLocalStore

func NewLocalStore(opts LocalStoreOpts) (*LocalStore, error)

func (*LocalStore) Get

func (c *LocalStore) Get(ctx context.Context, key entities.Hash) (content []byte, retErr error)

func (*LocalStore) GetMeta

func (c *LocalStore) GetMeta(ctx context.Context, key entities.Hash, meta string) (content []byte, retErr error)

func (*LocalStore) GetXAttr

func (c *LocalStore) GetXAttr(ctx context.Context, key entities.Hash, attr string) (string, error)

func (*LocalStore) Has

func (c *LocalStore) Has(key entities.Hash) (bool, error)

func (*LocalStore) HasHex

func (c *LocalStore) HasHex(hexStr string) bool

HasHex checks if a file exists on disk for the given hex-encoded key.

func (*LocalStore) MetaSize

func (c *LocalStore) MetaSize(ctx context.Context, key entities.Hash, meta string) (int64, error)

func (*LocalStore) NotifyRead

func (c *LocalStore) NotifyRead(ctx context.Context, key entities.Hash) error

func (*LocalStore) NotifyWrite

func (c *LocalStore) NotifyWrite(ctx context.Context, key entities.Hash) error

func (*LocalStore) ObjectHeader

func (c *LocalStore) ObjectHeader(ctx context.Context, key entities.Hash) (hdr entities.ObjectHeader, retErr error)

func (*LocalStore) OpenFile

func (c *LocalStore) OpenFile(ctx context.Context, id entities.Hash) (io.ReadCloser, error)

OpenFile returns a file corresponding to the blob, opened for reading.

func (*LocalStore) Path

func (c *LocalStore) Path(id entities.Hash) string

Path returns the local path from where the file can be read.

func (*LocalStore) PathHex

func (c *LocalStore) PathHex(str string) string

PathHex returns the sharded on-disk filesystem path for a hex-encoded key (supporting arbitrary lengths, such as a 40-character SHA-1 or 64-character SHA-256).

Sharding divides cached files across subdirectories to prevent large directory scaling bottlenecks (e.g., filesystem lookup overhead with hundreds of thousands of files in a single directory).

Examples for levels = 2:

  • SHA-1: <dir>/e69/de29bb2d1d6434b8b29ae775ad8c2e48c5391
  • SHA-256: <dir>/e3b/0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855

func (*LocalStore) PathMeta

func (c *LocalStore) PathMeta(id entities.Hash, meta string) string

func (*LocalStore) Put

func (c *LocalStore) Put(ctx context.Context, key entities.Hash, content []byte) error

func (*LocalStore) PutFile

func (c *LocalStore) PutFile(ctx context.Context, key entities.Hash, filename string) error

func (*LocalStore) PutMeta

func (c *LocalStore) PutMeta(ctx context.Context, key entities.Hash, meta string, content []byte) error

func (*LocalStore) Remove

func (c *LocalStore) Remove(key entities.Hash) error

func (*LocalStore) RemoveMeta

func (c *LocalStore) RemoveMeta(key entities.Hash, meta string) error

func (*LocalStore) Size

func (c *LocalStore) Size(ctx context.Context, key entities.Hash) (int64, error)

func (*LocalStore) Stat

func (*LocalStore) Write

func (c *LocalStore) Write(ctx context.Context, id entities.Hash, r io.Reader, beforeRename func(string) error) error

Write uses the provided reader to write the file contents into the cache at the provided hash. `beforeRename` allows callers to modify the file before it is renamed to its final location.

func (*LocalStore) WriteHex

func (c *LocalStore) WriteHex(ctx context.Context, hexStr string, r io.Reader, beforeRename func(string) error) error

WriteHex writes content at the given hex path (e.g. SHA-256 CAS blob).

type LocalStoreOpts

type LocalStoreOpts struct {
	Dir          string
	Levels       int
	Notify       Notify
	CompressMode CompressMode
	Fsync        bool
}

type LogRefStore

type LogRefStore struct {
	// contains filtered or unexported fields
}

func NewLogRefStore

func NewLogRefStore(dir string) (*LogRefStore, error)

func (*LogRefStore) Close

func (s *LogRefStore) Close() error

func (*LogRefStore) Get

func (s *LogRefStore) Get(server string, project string, refs []string) ([]entities.Hash, error)

func (*LogRefStore) Put

func (s *LogRefStore) Put(server string, project string, refs []entities.RefHash) error

func (*LogRefStore) Search

func (s *LogRefStore) Search(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)

type MapStore

type MapStore struct {
	// contains filtered or unexported fields
}

func NewMapStore

func NewMapStore(dir string, levels int) (*MapStore, error)

func (*MapStore) AddMapResult

func (c *MapStore) AddMapResult(from, to entities.Hash) (err error)

AddMapResult is NOT safe to be run concurrently

func (*MapStore) MapResults

func (c *MapStore) MapResults(id entities.Hash) (hashes []entities.Hash, retErr error)

type Notify

type Notify struct {
	PutFile NotifyFunc
	Write   NotifyFunc
	Read    NotifyFunc
}

type NotifyFunc

type NotifyFunc func(ctx context.Context, key entities.Hash) error

type RefStore

type RefStore interface {
	Put(server string, project string, refs []entities.RefHash) error
	Get(server string, project string, refs []string) ([]entities.Hash, error)
	Search(server string, project string, refPrefix string) ([]entities.ProjectRefHash, error)
	Close() error
}

Jump to

Keyboard shortcuts

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