Documentation
¶
Overview ¶
Package cache saves and restores cache archives via the Buildkite cache API.
The CLI entry points are RunSave and RunRestore in cache.go. Internally they build a client (a configured handle bundling the API client, storage bucket and the expanded cache definitions) and dispatch Save/Restore per cache ID.
Index ¶
- Variables
- func RunRestore(ctx context.Context, l logger.Logger, apiClient *api.Client, cfg Config) error
- func RunSave(ctx context.Context, l logger.Logger, apiClient *api.Client, cfg Config) error
- type ArchiveMetrics
- type Config
- type ProgressCallback
- type RestoreResult
- type SaveResult
- type TransferMetrics
Constants ¶
This section is empty.
Variables ¶
var ( // ErrCacheNotFound is returned when a requested cache ID doesn't exist in // the loaded configuration. ErrCacheNotFound = errors.New("cache not found") // ErrInvalidConfiguration is returned when configuration validation fails // while building a client. ErrInvalidConfiguration = errors.New("invalid configuration") )
Sentinel errors for common scenarios.
Functions ¶
func RunRestore ¶ added in v3.127.2
RunRestore restores caches based on the provided configuration and logs results as each cache is processed.
Types ¶
type ArchiveMetrics ¶ added in v3.127.2
type ArchiveMetrics struct {
// Size is the total size of the archive file in bytes (compressed).
Size int64
// WrittenBytes is the uncompressed size of all files in bytes.
WrittenBytes int64
// WrittenEntries is the number of files/directories in the archive.
WrittenEntries int64
// CompressionRatio is WrittenBytes / Size.
CompressionRatio float64
// Sha256Sum is the SHA-256 hash of the archive file (save only).
Sha256Sum string
// Duration is how long the archive build or extraction took.
Duration time.Duration
// Paths are the filesystem paths that were archived or extracted.
Paths []string
}
ArchiveMetrics contains metrics about archive build and extraction operations.
type Config ¶
type Config struct {
// BucketURL is the URL of the bucket (e.g., s3://bucket-name)
BucketURL string
// Branch is the branch associated with the cache
Branch string
// Pipeline is the pipeline slug for this cache
Pipeline string
// Organization is the organization slug for this cache
Organization string
// CacheConfigFile is the path to the cache configuration YAML file
CacheConfigFile string
// Ids is a list of cache IDs (if empty, processes all caches)
Ids []string
// Concurrency is the number of concurrent cache operations
Concurrency int
}
Config holds the configuration for cache operations.
type ProgressCallback ¶ added in v3.127.2
ProgressCallback is invoked during Save and Restore to report progress.
Implementations must be thread-safe; the callback may be called from multiple goroutines. See save.go and restore.go for the stage values.
type RestoreResult ¶ added in v3.127.2
type RestoreResult struct {
// CacheHit indicates whether the exact cache key was found.
CacheHit bool
// CacheRestored indicates whether any cache was restored (including fallbacks).
CacheRestored bool
// Key is the actual cache key that was restored.
Key string
// FallbackUsed indicates whether a fallback key was used.
FallbackUsed bool
// Archive contains information about the archive that was extracted.
Archive ArchiveMetrics
// Transfer contains information about the download operation.
Transfer TransferMetrics
// ExpiresAt indicates when this cache entry will expire.
ExpiresAt time.Time
// TotalDuration is the end-to-end duration of the restore operation.
TotalDuration time.Duration
}
RestoreResult contains detailed information about a cache restore operation.
type SaveResult ¶ added in v3.127.2
type SaveResult struct {
// CacheEntryCreated indicates whether a new cache entry was created.
// false means the cache already existed and no upload occurred.
// When false, Transfer will be nil since no upload was performed.
CacheEntryCreated bool
// Key is the actual cache key that was used (after template expansion).
Key string
// UploadID is the unique identifier for this upload (if created).
// Empty if CacheEntryCreated is false.
UploadID string
// Archive contains information about the archive that was built.
Archive ArchiveMetrics
// Transfer contains information about the upload (if performed).
// Nil if CacheEntryCreated is false (cache already existed).
Transfer *TransferMetrics
// TotalDuration is the end-to-end duration of the save operation.
TotalDuration time.Duration
}
SaveResult contains detailed information about a cache save operation.
type TransferMetrics ¶ added in v3.127.2
type TransferMetrics struct {
// BytesTransferred is the number of bytes uploaded or downloaded.
BytesTransferred int64
// TransferSpeed is the transfer rate in MB/s.
TransferSpeed float64
// Duration is how long the transfer took.
Duration time.Duration
// RequestID is the provider-specific request identifier for debugging.
RequestID string
// PartCount is the number of parts used in multipart transfer (0 if not multipart).
PartCount int
// Concurrency is the number of concurrent uploads/downloads used.
Concurrency int
}
TransferMetrics contains metrics about upload and download operations.