Documentation
¶
Index ¶
- func GetCacheKey(prefix string, version string, additional ...string) string
- func GetCacheKeyForBuild(goVersion string, buildTags string) string
- func GetCacheKeyForDockerLayers(imageName string, dockerfilePath string) string
- func GetCacheKeyForModules(goVersion string) string
- func IsGitHubActions() bool
- func MountCacheVolume(container *dagger.Container, cacheKey string, mountPath string, ...) *dagger.Container
- type DaggerCacheManager
- func (d *DaggerCacheManager) Get(_ context.Context, _ string) ([]byte, error)
- func (d *DaggerCacheManager) GetCacheVolume(key string) *dagger.CacheVolume
- func (d *DaggerCacheManager) GetWithFallback(_ context.Context, _ string, _ time.Duration, fallback func() ([]byte, error)) ([]byte, error)
- func (d *DaggerCacheManager) Invalidate(_ context.Context, key string) error
- func (d *DaggerCacheManager) Set(_ context.Context, _ string, _ []byte, _ time.Duration) error
- func (d *DaggerCacheManager) WarmUp(_ context.Context, keys []string, _ func(string) ([]byte, error)) error
- type GitHubActionsCache
- func (c *GitHubActionsCache) Get(_ context.Context, key string) ([]byte, error)
- func (c *GitHubActionsCache) GetWithFallback(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error)
- func (c *GitHubActionsCache) Invalidate(_ context.Context, key string) error
- func (c *GitHubActionsCache) Set(_ context.Context, key string, data []byte, _ time.Duration) error
- func (c *GitHubActionsCache) WarmUp(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
- type IncrementalCache
- func (c *IncrementalCache) Get(_ context.Context, key string) ([]byte, error)
- func (c *IncrementalCache) GetCacheKeyForFiles(files []string) (string, error)
- func (c *IncrementalCache) GetWithFallback(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error)
- func (c *IncrementalCache) Invalidate(_ context.Context, key string) error
- func (c *IncrementalCache) IsCacheValid(ctx context.Context, cacheKey string, files []string) (bool, error)
- func (c *IncrementalCache) Set(_ context.Context, key string, data []byte, _ time.Duration) error
- func (c *IncrementalCache) WarmUp(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
- type LocalFileCache
- func (c *LocalFileCache) Get(_ context.Context, key string) ([]byte, error)
- func (c *LocalFileCache) GetWithFallback(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error)
- func (c *LocalFileCache) Invalidate(_ context.Context, key string) error
- func (c *LocalFileCache) Set(_ context.Context, key string, data []byte, ttl time.Duration) error
- func (c *LocalFileCache) WarmUp(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
- type Metrics
- func (m *Metrics) GetAverageLatency() time.Duration
- func (m *Metrics) GetErrors() int64
- func (m *Metrics) GetHitRate() float64
- func (m *Metrics) GetHits() int64
- func (m *Metrics) GetMisses() int64
- func (m *Metrics) GetTotalRequests() int64
- func (m *Metrics) RecordError()
- func (m *Metrics) RecordHit(latency time.Duration)
- func (m *Metrics) RecordMiss(latency time.Duration)
- func (m *Metrics) Reset()
- type MetricsWrapper
- func (w *MetricsWrapper) Get(ctx context.Context, key string) ([]byte, error)
- func (w *MetricsWrapper) GetMetrics() *Metrics
- func (w *MetricsWrapper) GetWithFallback(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error)
- func (w *MetricsWrapper) Invalidate(ctx context.Context, key string) error
- func (w *MetricsWrapper) Set(ctx context.Context, key string, data []byte, ttl time.Duration) error
- func (w *MetricsWrapper) WarmUp(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
- type MockStrategy
- func (m *MockStrategy) Get(ctx context.Context, key string) ([]byte, error)
- func (m *MockStrategy) GetWithFallback(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error)
- func (m *MockStrategy) Invalidate(ctx context.Context, key string) error
- func (m *MockStrategy) Set(ctx context.Context, key string, data []byte, ttl time.Duration) error
- func (m *MockStrategy) WarmUp(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
- type Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetCacheKey ¶
GetCacheKey generates a cache key for GitHub Actions cache action. The key should be unique per cache entry and include version information.
func GetCacheKeyForBuild ¶
GetCacheKeyForBuild generates a cache key for build artifacts.
func GetCacheKeyForDockerLayers ¶
GetCacheKeyForDockerLayers generates a cache key for Docker image layers.
func GetCacheKeyForModules ¶
GetCacheKeyForModules generates a cache key for Go modules.
func IsGitHubActions ¶
func IsGitHubActions() bool
IsGitHubActions checks if we're running in GitHub Actions environment.
func MountCacheVolume ¶
func MountCacheVolume(container *dagger.Container, cacheKey string, mountPath string, manager *DaggerCacheManager) *dagger.Container
MountCacheVolume mounts a cache volume in a container at the specified path.
Parameters:
- container: The Dagger container.
- cacheKey: The cache key.
- mountPath: The path where to mount the cache.
Returns:
- The container with cache volume mounted.
Types ¶
type DaggerCacheManager ¶
type DaggerCacheManager struct {
// contains filtered or unexported fields
}
DaggerCacheManager manages cache for Dagger container layers. It uses Dagger's built-in cache volumes for efficient layer caching.
func NewDaggerCacheManager ¶
func NewDaggerCacheManager(client *dagger.Client) *DaggerCacheManager
NewDaggerCacheManager creates a new DaggerCacheManager.
Parameters:
- client: The Dagger client for cache operations.
Returns:
- A new DaggerCacheManager instance.
func (*DaggerCacheManager) Get ¶
Get is not directly applicable to Dagger cache volumes. Dagger handles cache automatically through mounted volumes.
func (*DaggerCacheManager) GetCacheVolume ¶
func (d *DaggerCacheManager) GetCacheVolume(key string) *dagger.CacheVolume
GetCacheVolume returns or creates a Dagger cache volume for the given key.
Parameters:
- key: The cache key identifier.
Returns:
- A Dagger CacheVolume for the key.
func (*DaggerCacheManager) GetWithFallback ¶
func (d *DaggerCacheManager) GetWithFallback(_ context.Context, _ string, _ time.Duration, fallback func() ([]byte, error)) ([]byte, error)
GetWithFallback is not directly applicable to Dagger cache.
func (*DaggerCacheManager) Invalidate ¶
func (d *DaggerCacheManager) Invalidate(_ context.Context, key string) error
Invalidate removes a cache volume (clears the cache).
type GitHubActionsCache ¶
type GitHubActionsCache struct {
// contains filtered or unexported fields
}
GitHubActionsCache implements Strategy using GitHub Actions cache. This cache strategy integrates with GitHub Actions cache action. Note: Actual cache operations are handled by GitHub Actions cache action, this implementation provides the interface and helper methods.
func NewGitHubActionsCache ¶
func NewGitHubActionsCache(cacheDir string) *GitHubActionsCache
NewGitHubActionsCache creates a new GitHubActionsCache.
Parameters:
- cacheDir: Directory where cache files are stored (defaults to .cache if empty).
Returns:
- A new GitHubActionsCache instance.
func (*GitHubActionsCache) Get ¶
Get retrieves a value from cache by key. In GitHub Actions, cache is restored by the cache action before this runs. This method reads from the local cache directory.
func (*GitHubActionsCache) GetWithFallback ¶
func (c *GitHubActionsCache) GetWithFallback(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
GetWithFallback retrieves a value from cache, or executes fallback function if not found.
func (*GitHubActionsCache) Invalidate ¶
func (c *GitHubActionsCache) Invalidate(_ context.Context, key string) error
Invalidate removes a value from cache by key.
type IncrementalCache ¶
type IncrementalCache struct {
// contains filtered or unexported fields
}
IncrementalCache implements Strategy for file-based incremental caching. It caches results based on file content hashes, invalidating only when files change.
func NewIncrementalCache ¶
func NewIncrementalCache(baseDir string) *IncrementalCache
NewIncrementalCache creates a new IncrementalCache.
Parameters:
- baseDir: Base directory for cache files (defaults to .cache/incremental if empty).
Returns:
- A new IncrementalCache instance.
func (*IncrementalCache) GetCacheKeyForFiles ¶
func (c *IncrementalCache) GetCacheKeyForFiles(files []string) (string, error)
GetCacheKeyForFiles generates a cache key based on file paths and their content hashes.
Parameters:
- files: List of file paths to include in the cache key.
Returns:
- A cache key string based on file hashes.
func (*IncrementalCache) GetWithFallback ¶
func (c *IncrementalCache) GetWithFallback(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
GetWithFallback retrieves a value from cache, or executes fallback function if not found.
func (*IncrementalCache) Invalidate ¶
func (c *IncrementalCache) Invalidate(_ context.Context, key string) error
Invalidate removes a value from cache by key.
func (*IncrementalCache) IsCacheValid ¶
func (c *IncrementalCache) IsCacheValid(ctx context.Context, cacheKey string, files []string) (bool, error)
IsCacheValid checks if cache is still valid for the given files.
Parameters:
- cacheKey: The cache key to check.
- files: List of file paths to validate against.
Returns:
- True if cache is valid, false otherwise.
type LocalFileCache ¶
type LocalFileCache struct {
// contains filtered or unexported fields
}
LocalFileCache implements Strategy using local file system. Suitable for development and local CI/CD runs.
func NewLocalFileCache ¶
func NewLocalFileCache(baseDir string) *LocalFileCache
NewLocalFileCache creates a new LocalFileCache.
Parameters:
- baseDir: Base directory for cache files (defaults to .cache if empty).
Returns:
- A new LocalFileCache instance.
func (*LocalFileCache) GetWithFallback ¶
func (c *LocalFileCache) GetWithFallback(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
GetWithFallback retrieves a value from cache, or executes fallback function if not found.
func (*LocalFileCache) Invalidate ¶
func (c *LocalFileCache) Invalidate(_ context.Context, key string) error
Invalidate removes a value from cache by key.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics tracks cache performance metrics.
func (*Metrics) GetAverageLatency ¶
GetAverageLatency returns the average latency for cache operations.
func (*Metrics) GetHitRate ¶
GetHitRate returns the cache hit rate as a percentage.
func (*Metrics) GetTotalRequests ¶
GetTotalRequests returns the total number of cache requests.
func (*Metrics) RecordMiss ¶
RecordMiss records a cache miss.
type MetricsWrapper ¶
type MetricsWrapper struct {
// contains filtered or unexported fields
}
MetricsWrapper wraps a Strategy with metrics collection.
func NewMetricsWrapper ¶
func NewMetricsWrapper(strategy Strategy) *MetricsWrapper
NewMetricsWrapper creates a new MetricsWrapper.
func (*MetricsWrapper) GetMetrics ¶
func (w *MetricsWrapper) GetMetrics() *Metrics
GetMetrics returns the metrics instance.
func (*MetricsWrapper) GetWithFallback ¶
func (w *MetricsWrapper) GetWithFallback(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
GetWithFallback retrieves a value with fallback and metrics tracking.
func (*MetricsWrapper) Invalidate ¶
func (w *MetricsWrapper) Invalidate(ctx context.Context, key string) error
Invalidate removes a value from cache.
type MockStrategy ¶
type MockStrategy struct {
GetFunc func(ctx context.Context, key string) ([]byte, error)
SetFunc func(ctx context.Context, key string, data []byte, ttl time.Duration) error
InvalidateFunc func(ctx context.Context, key string) error
GetWithFallbackFunc func(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
WarmUpFunc func(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
}
MockStrategy implements Strategy interface for testing.
func NewMockStrategy ¶
func NewMockStrategy() *MockStrategy
NewMockStrategy creates a new MockStrategy with default behavior.
func (*MockStrategy) GetWithFallback ¶
func (m *MockStrategy) GetWithFallback(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
GetWithFallback retrieves a value from cache, or executes fallback function if not found.
func (*MockStrategy) Invalidate ¶
func (m *MockStrategy) Invalidate(ctx context.Context, key string) error
Invalidate removes a value from cache by key.
type Strategy ¶
type Strategy interface {
// Get retrieves a value from cache by key.
Get(ctx context.Context, key string) ([]byte, error)
// Set stores a value in cache with the specified key and TTL.
Set(ctx context.Context, key string, data []byte, ttl time.Duration) error
// Invalidate removes a value from cache by key.
Invalidate(ctx context.Context, key string) error
// GetWithFallback retrieves a value from cache, or executes fallback function if not found.
GetWithFallback(ctx context.Context, key string, ttl time.Duration, fallback func() ([]byte, error)) ([]byte, error)
// WarmUp pre-warms the cache with the specified keys.
WarmUp(ctx context.Context, keys []string, generator func(string) ([]byte, error)) error
}
Strategy defines the interface for cache strategies. Different strategies can use local files, distributed caches, CI/CD caches, etc.