Documentation
¶
Index ¶
- type AsyncBackendStats
- type AsyncBackendWriter
- func (abw *AsyncBackendWriter) Clear() error
- func (abw *AsyncBackendWriter) Close() error
- func (abw *AsyncBackendWriter) Get(actionID []byte) (outputID []byte, body io.ReadCloser, size int64, putTime *time.Time, miss bool, ...)
- func (abw *AsyncBackendWriter) Put(actionID, outputID []byte, body io.Reader, bodySize int64) error
- func (abw *AsyncBackendWriter) Stats() AsyncBackendStats
- type Backend
- type Debug
- type Error
- func (e *Error) Clear() error
- func (e *Error) Close() error
- func (e *Error) Get(actionID []byte) ([]byte, io.ReadCloser, int64, *time.Time, bool, error)
- func (e *Error) GetStats() (putErrors, getErrors, closeErrors, clearErrors int64)
- func (e *Error) Put(actionID, outputID []byte, body io.Reader, bodySize int64) error
- type GCS
- type Noop
- type S3
- type S3Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AsyncBackendStats ¶
type AsyncBackendStats struct {
StartedPuts int64
SuccessPuts int64
FailedPuts int64
TotalPutTimeMicros int64
}
AsyncBackendStats holds statistics for the async backend writer
type AsyncBackendWriter ¶
type AsyncBackendWriter struct {
// contains filtered or unexported fields
}
AsyncBackendWriter wraps a Backend and provides asynchronous PUT operations. GET operations are still synchronous as they're in the critical path for builds. PUT operations spawn a goroutine on demand.
func NewAsyncBackendWriter ¶
func NewAsyncBackendWriter( backend Backend, logger *slog.Logger, ) *AsyncBackendWriter
func (*AsyncBackendWriter) Clear ¶
func (abw *AsyncBackendWriter) Clear() error
Clear passes through to the underlying backend
func (*AsyncBackendWriter) Close ¶
func (abw *AsyncBackendWriter) Close() error
Close gracefully shuts down the async writer and waits for all in-flight operations to complete. It also closes the underlying backend.
func (*AsyncBackendWriter) Get ¶
func (abw *AsyncBackendWriter) Get(actionID []byte) (outputID []byte, body io.ReadCloser, size int64, putTime *time.Time, miss bool, err error)
Get passes through to the underlying backend (synchronous). GET operations remain synchronous as they're in the critical path.
func (*AsyncBackendWriter) Put ¶
Put spawns a goroutine to execute the PUT operation asynchronously. The body is copied to avoid holding references to the original data.
func (*AsyncBackendWriter) Stats ¶
func (abw *AsyncBackendWriter) Stats() AsyncBackendStats
Stats returns current statistics about the async writer
type Backend ¶
type Backend interface {
// Put stores an object in the backend storage.
// actionID is the cache key, outputID is stored with the body,
// body is the content to store, and bodySize is the size in bytes.
// The backend stores the data in its storage system and returns nil on success.
Put(actionID, outputID []byte, body io.Reader, bodySize int64) error
// Get retrieves an object from the backend storage.
// actionID is the cache key to look up.
// Returns outputID, body (as io.ReadCloser), size, putTime, and whether it was a miss.
// The caller is responsible for closing the returned ReadCloser.
// On a cache miss, returns miss=true and body=nil.
Get(actionID []byte) (outputID []byte, body io.ReadCloser, size int64, putTime *time.Time, miss bool, err error)
// Close performs any cleanup operations needed by the backend.
Close() error
// Clear removes all entries from the cache backend storage.
Clear() error
}
Backend defines the interface for cache storage backends.
Implementations can be swapped to use different storage mechanisms. The backend is responsible ONLY for storing/retrieving data from its storage system. The server (server.go) is responsible for managing the local disk cache that Go accesses.
Implementations must be thread-safe and support concurrent operations, but the caller (server.go) guarantees that there will never be two inflight operations of the same type for the same actionID (singleflight) which makes implementing the backends simpler (no need to worry about locking at the filesystem layer).
type Debug ¶
type Debug struct {
// contains filtered or unexported fields
}
Debug wraps any Backend and adds debug logging. This allows any backend implementation to have debug logging without coupling the debug logic to the backend implementation.
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error wraps any Backend and randomly returns errors based on a configured percentage. This is useful for testing error handling and resilience.
func NewError ¶
NewError creates a new error-injecting wrapper around an existing backend. errorRate should be between 0.0 (no errors) and 1.0 (all errors fail).
func (*Error) Get ¶
Get retrieves an object from the backend storage, potentially returning an error.
type GCS ¶ added in v1.5.0
type GCS struct {
// contains filtered or unexported fields
}
GCS implements Backend using Google Cloud Storage. This backend only handles GCS operations; local disk caching is handled by server.go.
func NewGCS ¶ added in v1.5.0
NewGCS creates a new GCS-based cache backend. bucket is the GCS bucket name where cache files will be stored. prefix is an optional prefix for all GCS object names (e.g., "cache/" or "").
type Noop ¶
type Noop struct{}
Noop is a no-op backend that does nothing. This is useful when using only local disk caching (via server.go's localCache) without any distributed/remote backend storage.
func (*Noop) Clear ¶
Clear does nothing. The local cache in server.go manages its own clearing if needed.
type S3 ¶
type S3 struct {
// contains filtered or unexported fields
}
S3 implements Backend using AWS S3. This backend only handles S3 operations; local disk caching is handled by server.go.
func NewS3 ¶
NewS3 creates a new S3-based cache backend. bucket is the S3 bucket name where cache files will be stored. prefix is an optional prefix for all S3 keys (e.g., "cache/" or ""). awsCfg provides explicit AWS configuration (region, credentials) resolved by the caller.
type S3Config ¶ added in v1.5.0
type S3Config struct {
Region string
AccessKeyID string
SecretAccessKey string
SessionToken string
UsePathStyle bool
}
S3Config holds AWS-specific configuration for the S3 backend. These are resolved from environment variables in main.go using the GOBUILDCACHE_-prefixed convention, allowing users to provide AWS credentials without polluting the environment for other processes (e.g., test binaries spawned by go test).