Documentation
¶
Overview ¶
Package cache provides build caching for faster rebuilds.
Package cache provides build caching for faster rebuilds.
Package cache provides build caching for faster rebuilds.
Index ¶
- Variables
- type BuildCacheManager
- type CacheKeyComponents
- type CacheStats
- type CachedBuild
- type CachedDetection
- type DetectionCache
- type DetectionCacheOption
- type InMemoryDetectionCache
- func (c *InMemoryDetectionCache) CleanupExpired(ctx context.Context) int
- func (c *InMemoryDetectionCache) Clear(ctx context.Context)
- func (c *InMemoryDetectionCache) Delete(ctx context.Context, repoURL, commitSHA string) error
- func (c *InMemoryDetectionCache) Get(ctx context.Context, repoURL, commitSHA string) (*models.DetectionResult, bool)
- func (c *InMemoryDetectionCache) Set(ctx context.Context, repoURL, commitSHA string, result *models.DetectionResult) error
- func (c *InMemoryDetectionCache) Size() int
- type Manager
- func (m *Manager) CheckCache(ctx context.Context, cacheKey string) (*CachedBuild, error)
- func (m *Manager) CleanupExpired(ctx context.Context) int
- func (m *Manager) GetCacheKey(ctx context.Context, job *models.BuildJob) (string, error)
- func (m *Manager) GetCacheStats(ctx context.Context) *CacheStats
- func (m *Manager) GetCachedArtifact(ctx context.Context, cacheKey string) (string, error)
- func (m *Manager) InvalidateCache(ctx context.Context, serviceID string) error
- func (m *Manager) InvalidateCacheKey(ctx context.Context, cacheKey string) error
- func (m *Manager) IsCacheHit(ctx context.Context, cacheKey string) bool
- func (m *Manager) ListCacheKeys(ctx context.Context) []string
- func (m *Manager) StoreCache(ctx context.Context, cacheKey string, result *models.BuildResult) error
- func (m *Manager) StoreCacheWithMetadata(ctx context.Context, cacheKey string, result *models.BuildResult, ...) error
- type ManagerOption
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNilBuildJob is returned when a nil build job is provided. ErrNilBuildJob = errors.New("build job is nil") // ErrEmptyCacheKey is returned when an empty cache key is provided. ErrEmptyCacheKey = errors.New("cache key is empty") // ErrCacheNotFound is returned when a cache entry is not found. ErrCacheNotFound = errors.New("cache entry not found") // ErrCacheExpired is returned when a cache entry has expired. ErrCacheExpired = errors.New("cache entry has expired") // ErrNilBuildResult is returned when a nil build result is provided. ErrNilBuildResult = errors.New("build result is nil") // ErrEmptyArtifact is returned when an empty artifact is provided. ErrEmptyArtifact = errors.New("artifact is empty") // ErrEmptyServiceID is returned when an empty service ID is provided. ErrEmptyServiceID = errors.New("service ID is empty") // ErrEmptyRepoURL is returned when an empty repository URL is provided. ErrEmptyRepoURL = errors.New("repository URL is empty") // ErrEmptyCommitSHA is returned when an empty commit SHA is provided. ErrEmptyCommitSHA = errors.New("commit SHA is empty") // ErrNilDetectionResult is returned when a nil detection result is provided. ErrNilDetectionResult = errors.New("detection result is nil") )
Cache errors.
Functions ¶
This section is empty.
Types ¶
type BuildCacheManager ¶
type BuildCacheManager interface {
// GetCacheKey generates a cache key for a build.
GetCacheKey(ctx context.Context, job *models.BuildJob) (string, error)
// CheckCache checks if a cached build exists.
CheckCache(ctx context.Context, cacheKey string) (*CachedBuild, error)
// StoreCache stores a build result in cache.
StoreCache(ctx context.Context, cacheKey string, result *models.BuildResult) error
// InvalidateCache invalidates cache for a service.
InvalidateCache(ctx context.Context, serviceID string) error
}
BuildCacheManager handles build caching for faster rebuilds.
type CacheKeyComponents ¶
type CacheKeyComponents struct {
// SourceHash is the git commit SHA or source identifier.
SourceHash string `json:"source_hash"`
// DepsHash is the hash of dependency lock files (go.sum, package-lock.json, Cargo.lock).
DepsHash string `json:"deps_hash"`
// ConfigHash is the hash of the build configuration.
ConfigHash string `json:"config_hash"`
// Strategy is the build strategy used.
Strategy models.BuildStrategy `json:"strategy"`
// BuildType is the build output type.
BuildType models.BuildType `json:"build_type"`
}
CacheKeyComponents contains the components used to generate a cache key.
type CacheStats ¶
type CacheStats struct {
TotalEntries int `json:"total_entries"`
TotalServices int `json:"total_services"`
ExpiredEntries int `json:"expired_entries"`
}
CacheStats contains statistics about the cache.
type CachedBuild ¶
type CachedBuild struct {
CacheKey string `json:"cache_key"`
Artifact string `json:"artifact"`
BuildType models.BuildType `json:"build_type"`
CreatedAt time.Time `json:"created_at"`
SourceHash string `json:"source_hash"`
DepsHash string `json:"deps_hash"`
ConfigHash string `json:"config_hash"`
}
CachedBuild represents a cached build result.
type CachedDetection ¶
type CachedDetection struct {
RepoURL string `json:"repo_url"`
CommitSHA string `json:"commit_sha"`
Result *models.DetectionResult `json:"result"`
CreatedAt time.Time `json:"created_at"`
}
CachedDetection represents a cached detection result.
type DetectionCache ¶
type DetectionCache interface {
// Get retrieves cached detection results for a commit.
Get(ctx context.Context, repoURL, commitSHA string) (*models.DetectionResult, bool)
// Set stores detection results for a commit.
Set(ctx context.Context, repoURL, commitSHA string, result *models.DetectionResult) error
}
DetectionCache caches detection results by commit SHA. **Validates: Requirements 4.3**
type DetectionCacheOption ¶
type DetectionCacheOption func(*InMemoryDetectionCache)
DetectionCacheOption is a functional option for configuring InMemoryDetectionCache.
func WithDetectionTTL ¶
func WithDetectionTTL(ttl time.Duration) DetectionCacheOption
WithDetectionTTL sets the time-to-live for cached detections.
type InMemoryDetectionCache ¶
type InMemoryDetectionCache struct {
// contains filtered or unexported fields
}
InMemoryDetectionCache implements DetectionCache with an in-memory store. It is thread-safe and supports TTL-based expiration. **Validates: Requirements 4.3**
func NewInMemoryDetectionCache ¶
func NewInMemoryDetectionCache(opts ...DetectionCacheOption) *InMemoryDetectionCache
NewInMemoryDetectionCache creates a new InMemoryDetectionCache with default settings. Default TTL is 24 hours.
func (*InMemoryDetectionCache) CleanupExpired ¶
func (c *InMemoryDetectionCache) CleanupExpired(ctx context.Context) int
CleanupExpired removes expired entries from the cache. Returns the number of entries removed.
func (*InMemoryDetectionCache) Clear ¶
func (c *InMemoryDetectionCache) Clear(ctx context.Context)
Clear removes all cached detection results.
func (*InMemoryDetectionCache) Delete ¶
func (c *InMemoryDetectionCache) Delete(ctx context.Context, repoURL, commitSHA string) error
Delete removes a cached detection result.
func (*InMemoryDetectionCache) Get ¶
func (c *InMemoryDetectionCache) Get(ctx context.Context, repoURL, commitSHA string) (*models.DetectionResult, bool)
Get retrieves cached detection results for a commit. Returns the cached result and true if found and not expired, nil and false otherwise. **Validates: Requirements 4.3**
func (*InMemoryDetectionCache) Set ¶
func (c *InMemoryDetectionCache) Set(ctx context.Context, repoURL, commitSHA string, result *models.DetectionResult) error
Set stores detection results for a commit. **Validates: Requirements 4.3**
func (*InMemoryDetectionCache) Size ¶
func (c *InMemoryDetectionCache) Size() int
Size returns the number of cached entries.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager implements the BuildCacheManager interface.
func NewManager ¶
func NewManager() *Manager
NewManager creates a new Manager with default settings.
func NewManagerWithOptions ¶
func NewManagerWithOptions(opts ...ManagerOption) *Manager
NewManagerWithOptions creates a new Manager with custom options.
func (*Manager) CheckCache ¶
CheckCache checks if a cached build exists for the given cache key.
func (*Manager) CleanupExpired ¶
CleanupExpired removes expired entries from the cache.
func (*Manager) GetCacheKey ¶
GetCacheKey generates a cache key for a build job. The cache key is a hash of: - Source hash (git commit SHA) - Dependencies hash (go.sum, package-lock.json, Cargo.lock) - Build config hash - Build strategy - Build type
func (*Manager) GetCacheStats ¶
func (m *Manager) GetCacheStats(ctx context.Context) *CacheStats
GetCacheStats returns statistics about the cache.
func (*Manager) GetCachedArtifact ¶
GetCachedArtifact returns the artifact for a cache key if it exists.
func (*Manager) InvalidateCache ¶
InvalidateCache invalidates all cached builds for a service.
func (*Manager) InvalidateCacheKey ¶
InvalidateCacheKey invalidates a specific cache entry.
func (*Manager) IsCacheHit ¶
IsCacheHit checks if a cache key exists and is valid.
func (*Manager) ListCacheKeys ¶
ListCacheKeys returns all cache keys in the cache.
func (*Manager) StoreCache ¶
func (m *Manager) StoreCache(ctx context.Context, cacheKey string, result *models.BuildResult) error
StoreCache stores a build result in the cache.
type ManagerOption ¶
type ManagerOption func(*Manager)
ManagerOption is a functional option for configuring Manager.
func WithTTL ¶
func WithTTL(ttl time.Duration) ManagerOption
WithTTL sets the time-to-live for cached builds.