cache

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package cache provides fine-grained file-level caching for monox.

Package cache provides Google Cloud Storage remote caching for monox.

Package cache provides caching infrastructure for monox.

Package cache provides AWS S3 remote caching for monox.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, hash string) (*api.CacheEntry, error)
	Put(ctx context.Context, entry *api.CacheEntry, outputs []string) error
	Has(ctx context.Context, hash string) (bool, error)
	Delete(ctx context.Context, hash string) error
	RestoreOutputs(ctx context.Context, hash string, projectPath string) error
	Close() error
}

Cache is the interface for cache implementations.

type CacheManifest

type CacheManifest struct {
	Version   int                   `json:"version"`
	Files     map[string]*FileHash  `json:"files"`
	Tasks     map[string]*TaskCache `json:"tasks"`
	UpdatedAt time.Time             `json:"updatedAt"`
}

CacheManifest tracks all cached files and their relationships.

type CacheStats

type CacheStats struct {
	Entries    int       `json:"entries"`
	Size       int64     `json:"size"`
	OldestTime time.Time `json:"oldest"`
	NewestTime time.Time `json:"newest"`
}

CacheStats holds cache statistics.

type DiffCache

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

DiffCache provides incremental caching based on file diffs.

func NewDiffCache

func NewDiffCache(cache *FineGrainedCache) *DiffCache

NewDiffCache creates a diff-based cache.

func (*DiffCache) GetAffectedTasks

func (d *DiffCache) GetAffectedTasks() []string

GetAffectedTasks returns tasks affected by file changes.

func (*DiffCache) IsChanged

func (d *DiffCache) IsChanged(path string) bool

IsChanged checks if a file is marked as changed.

func (*DiffCache) MarkChanged

func (d *DiffCache) MarkChanged(path string)

MarkChanged marks a file as changed.

func (*DiffCache) MarkDeleted

func (d *DiffCache) MarkDeleted(path string)

MarkDeleted marks a file as deleted.

type FileHash

type FileHash struct {
	Path         string    `json:"path"`
	ContentHash  string    `json:"contentHash"`
	ModTime      time.Time `json:"modTime"`
	Size         int64     `json:"size"`
	Dependencies []string  `json:"dependencies,omitempty"`
}

FileHash stores hash information for a single file.

type FileRef

type FileRef struct {
	Path string `json:"path"`
	Hash string `json:"hash"`
}

FileRef references a file with its hash.

type FineGrainedCache

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

FineGrainedCache provides file-level caching for improved cache hits.

func NewFineGrainedCache

func NewFineGrainedCache(cacheDir, workspaceRoot string) (*FineGrainedCache, error)

NewFineGrainedCache creates a new fine-grained cache.

func (*FineGrainedCache) CacheTask

func (c *FineGrainedCache) CacheTask(project, target string, inputFiles, outputFiles []string, duration int64) error

CacheTask stores a task's outputs with file-level granularity.

func (*FineGrainedCache) Close

func (c *FineGrainedCache) Close() error

Close closes the cache.

func (*FineGrainedCache) GetBlob

func (c *FineGrainedCache) GetBlob(hash string) ([]byte, error)

GetBlob retrieves content by hash.

func (*FineGrainedCache) HasBlob

func (c *FineGrainedCache) HasBlob(hash string) bool

HasBlob checks if a blob exists.

func (*FineGrainedCache) HashFile

func (c *FineGrainedCache) HashFile(path string) (*FileHash, error)

HashFile computes the hash of a file with caching.

func (*FineGrainedCache) HashFiles

func (c *FineGrainedCache) HashFiles(paths []string) ([]FileRef, error)

HashFiles computes hashes for multiple files in parallel.

func (*FineGrainedCache) LookupTask

func (c *FineGrainedCache) LookupTask(project, target string, inputFiles []string) (*TaskCache, bool, error)

LookupTask checks if a task can be restored from cache.

func (*FineGrainedCache) Prune

func (c *FineGrainedCache) Prune(maxAge time.Duration, maxSize int64) error

Prune removes old cache entries.

func (*FineGrainedCache) RestoreFile

func (c *FineGrainedCache) RestoreFile(hash, dstPath string) error

RestoreFile restores a file from cache.

func (*FineGrainedCache) RestoreTask

func (c *FineGrainedCache) RestoreTask(project, target string) error

RestoreTask restores outputs from cache.

func (*FineGrainedCache) Stats

Stats returns cache statistics.

func (*FineGrainedCache) StoreBlob

func (c *FineGrainedCache) StoreBlob(hash string, content []byte) error

StoreBlob stores a file content by its hash.

func (*FineGrainedCache) StoreFile

func (c *FineGrainedCache) StoreFile(srcPath string) (string, error)

StoreFile stores a file and returns its hash.

type FineGrainedCacheStats

type FineGrainedCacheStats struct {
	TotalFiles    int       `json:"totalFiles"`
	TotalBlobs    int       `json:"totalBlobs"`
	TotalTasks    int       `json:"totalTasks"`
	BlobSizeBytes int64     `json:"blobSizeBytes"`
	HitRate       float64   `json:"hitRate"`
	MissRate      float64   `json:"missRate"`
	OldestEntry   time.Time `json:"oldestEntry"`
	NewestEntry   time.Time `json:"newestEntry"`
}

FineGrainedCacheStats provides fine-grained cache statistics.

type GCSCache

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

GCSCache implements remote caching using Google Cloud Storage.

func NewGCSCache

func NewGCSCache(ctx context.Context, cfg GCSConfig, workspaceRoot string) (*GCSCache, error)

NewGCSCache creates a new GCS cache client.

func (*GCSCache) Close

func (c *GCSCache) Close() error

Close releases resources.

func (*GCSCache) Delete

func (c *GCSCache) Delete(ctx context.Context, hash string) error

Delete removes a cache entry from GCS.

func (*GCSCache) Get

func (c *GCSCache) Get(ctx context.Context, hash string) (*api.CacheEntry, error)

Get retrieves a cache entry from GCS.

func (*GCSCache) Has

func (c *GCSCache) Has(ctx context.Context, hash string) (bool, error)

Has checks if a cache entry exists in GCS.

func (*GCSCache) Put

func (c *GCSCache) Put(ctx context.Context, entry *api.CacheEntry, outputs []string) error

Put stores a cache entry to GCS.

func (*GCSCache) RestoreOutputs

func (c *GCSCache) RestoreOutputs(ctx context.Context, hash string, projectPath string) error

RestoreOutputs downloads cached outputs from GCS.

type GCSConfig

type GCSConfig struct {
	Bucket          string
	Prefix          string
	Project         string
	CredentialsFile string
	CredentialsJSON string
	ReadOnly        bool
}

GCSConfig holds GCS cache configuration.

type Hasher

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

Hasher computes cache keys for tasks.

func NewHasher

func NewHasher(workspaceRoot string, globalInputs []string) *Hasher

NewHasher creates a new cache key hasher.

func (*Hasher) ComputeTaskHash

func (h *Hasher) ComputeTaskHash(ctx context.Context, project *api.Project, task api.Task, deps []string, extras map[string]string) (string, error)

ComputeTaskHash computes the hash for a task.

type LocalCache

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

LocalCache implements filesystem-based caching.

func NewLocalCache

func NewLocalCache(cacheDir, workspaceRoot string) (*LocalCache, error)

NewLocalCache creates a new local filesystem cache.

func (*LocalCache) Close

func (c *LocalCache) Close() error

Close releases resources.

func (*LocalCache) Delete

func (c *LocalCache) Delete(ctx context.Context, hash string) error

Delete removes a cache entry.

func (*LocalCache) Get

func (c *LocalCache) Get(ctx context.Context, hash string) (*api.CacheEntry, error)

Get retrieves a cache entry.

func (*LocalCache) GetStats

func (c *LocalCache) GetStats() (*CacheStats, error)

GetStats returns cache statistics.

func (*LocalCache) Has

func (c *LocalCache) Has(ctx context.Context, hash string) (bool, error)

Has checks if a cache entry exists.

func (*LocalCache) Prune

func (c *LocalCache) Prune(ctx context.Context, maxAge time.Duration, maxSize int64) (int, error)

Prune removes old cache entries.

func (*LocalCache) Put

func (c *LocalCache) Put(ctx context.Context, entry *api.CacheEntry, outputs []string) error

Put stores a cache entry with outputs.

func (*LocalCache) RestoreOutputs

func (c *LocalCache) RestoreOutputs(ctx context.Context, hash string, projectPath string) error

RestoreOutputs restores cached outputs to the project directory.

type S3Cache

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

S3Cache implements remote caching using AWS S3.

func NewS3Cache

func NewS3Cache(ctx context.Context, cfg S3Config, workspaceRoot string) (*S3Cache, error)

NewS3Cache creates a new S3 cache client.

func (*S3Cache) Close

func (c *S3Cache) Close() error

Close releases resources.

func (*S3Cache) Delete

func (c *S3Cache) Delete(ctx context.Context, hash string) error

Delete removes a cache entry from S3.

func (*S3Cache) Get

func (c *S3Cache) Get(ctx context.Context, hash string) (*api.CacheEntry, error)

Get retrieves a cache entry from S3.

func (*S3Cache) Has

func (c *S3Cache) Has(ctx context.Context, hash string) (bool, error)

Has checks if a cache entry exists in S3.

func (*S3Cache) Put

func (c *S3Cache) Put(ctx context.Context, entry *api.CacheEntry, outputs []string) error

Put stores a cache entry to S3.

func (*S3Cache) RestoreOutputs

func (c *S3Cache) RestoreOutputs(ctx context.Context, hash string, projectPath string) error

RestoreOutputs downloads cached outputs from S3.

type S3Config

type S3Config struct {
	Bucket          string
	Region          string
	Prefix          string
	Endpoint        string
	AccessKeyID     string
	SecretAccessKey string
	ReadOnly        bool
}

S3Config holds S3 cache configuration.

type TaskCache

type TaskCache struct {
	Project     string    `json:"project"`
	Target      string    `json:"target"`
	InputHash   string    `json:"inputHash"`
	OutputHash  string    `json:"outputHash"`
	InputFiles  []FileRef `json:"inputFiles"`
	OutputFiles []FileRef `json:"outputFiles"`
	Duration    int64     `json:"durationMs"`
	CachedAt    time.Time `json:"cachedAt"`
}

TaskCache stores task-level cache with file granularity.

Jump to

Keyboard shortcuts

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