Documentation
¶
Overview ¶
Package cache provides domain logic for cache management operations including clearing directories, gathering cache information, and formatting byte sizes.
Index ¶
- Variables
- func ClearDirectory(dir, pattern string) (int64, int64, error)
- func InvalidateArtifact(cacheDir string, ttl time.Duration, kind, name, version string) error
- type ArtifactCache
- func (c *ArtifactCache) Dir() string
- func (c *ArtifactCache) Get(kind, name, version string) (content, bundleData []byte, ok bool, err error)
- func (c *ArtifactCache) Invalidate(kind, name, version string) error
- func (c *ArtifactCache) Put(kind, name, version, digest string, content, bundleData []byte) error
- func (c *ArtifactCache) TTL() time.Duration
- type ClearOutput
- type Info
- type InfoOutput
- type Kind
Constants ¶
This section is empty.
Variables ¶
var ValidKinds = []string{string(KindAll), string(KindHTTP), string(KindBuild), string(KindArtifact)}
ValidKinds lists all valid cache kinds.
Functions ¶
func ClearDirectory ¶
ClearDirectory removes files from a directory, optionally matching a pattern. Returns the number of files removed and total bytes reclaimed.
func InvalidateArtifact ¶ added in v0.6.0
InvalidateArtifact is a convenience function that creates a default ArtifactCache and invalidates the entry for the given kind, name, and optional version. The cacheDir and ttl are forwarded to NewArtifactCache.
This encapsulates the common pattern:
cache := NewArtifactCache(dir, ttl) cache.Invalidate(kind, name, version)
Types ¶
type ArtifactCache ¶ added in v0.6.0
type ArtifactCache struct {
// contains filtered or unexported fields
}
ArtifactCache is a disk-based TTL cache for catalog artifacts. It stores artifact content (and optional bundle data) in a structured directory layout: {dir}/{kind}/{safe(name@version)}/
Each cache entry contains:
- content - the primary artifact bytes (e.g., solution YAML)
- bundle.tar.gz - the bundle tar (if any)
- meta.json - creation timestamp and content digest
func NewArtifactCache ¶ added in v0.6.0
func NewArtifactCache(dir string, ttl time.Duration) *ArtifactCache
NewArtifactCache creates a new ArtifactCache rooted at dir with the given TTL. A zero TTL means entries never expire.
func (*ArtifactCache) Dir ¶ added in v0.6.0
func (c *ArtifactCache) Dir() string
Dir returns the root directory of the cache.
func (*ArtifactCache) Get ¶ added in v0.6.0
func (c *ArtifactCache) Get(kind, name, version string) (content, bundleData []byte, ok bool, err error)
Get retrieves cached content and bundle data for the given artifact. Returns (nil, nil, false, nil) on cache miss or expiry. Returns (nil, nil, false, err) on read errors.
func (*ArtifactCache) Invalidate ¶ added in v0.6.0
func (c *ArtifactCache) Invalidate(kind, name, version string) error
Invalidate removes a cached entry for the given artifact. Returns nil if the entry does not exist.
func (*ArtifactCache) Put ¶ added in v0.6.0
func (c *ArtifactCache) Put(kind, name, version, digest string, content, bundleData []byte) error
Put stores artifact content and optional bundle data in the cache. digest is the content digest returned by the catalog (e.g., "sha256:abc123..."). bundleData may be nil when the artifact has no bundle layer.
func (*ArtifactCache) TTL ¶ added in v0.6.0
func (c *ArtifactCache) TTL() time.Duration
TTL returns the configured TTL for cache entries.
type ClearOutput ¶
type ClearOutput struct {
RemovedFiles int64 `json:"removedFiles" yaml:"removedFiles"`
RemovedBytes int64 `json:"removedBytes" yaml:"removedBytes"`
RemovedHuman string `json:"reclaimedHuman" yaml:"reclaimedHuman"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
Name string `json:"name,omitempty" yaml:"name,omitempty"`
}
ClearOutput represents the result of a cache clear operation.
type Info ¶
type Info struct {
Name string `json:"name" yaml:"name"`
Path string `json:"path" yaml:"path"`
Size int64 `json:"size" yaml:"size"`
SizeHuman string `json:"sizeHuman" yaml:"sizeHuman"`
FileCount int64 `json:"fileCount" yaml:"fileCount"`
Description string `json:"description" yaml:"description"`
}
Info represents information about a cache directory.
func GetCacheInfo ¶
GetCacheInfo returns information about a cache directory.
type InfoOutput ¶
type InfoOutput struct {
Caches []Info `json:"caches" yaml:"caches"`
TotalSize int64 `json:"totalSize" yaml:"totalSize"`
TotalHuman string `json:"totalHuman" yaml:"totalHuman"`
TotalFiles int64 `json:"totalFiles" yaml:"totalFiles"`
}
InfoOutput represents aggregated information for multiple cache directories.
type Kind ¶
type Kind string
Kind represents the type of cache to clear.
const ( // KindAll clears all caches. KindAll Kind = "all" // KindHTTP clears the HTTP response cache. KindHTTP Kind = "http" // KindBuild clears the build cache (incremental build fingerprints). KindBuild Kind = "build" // KindArtifact clears the artifact cache (downloaded catalog artifacts with TTL). KindArtifact Kind = "artifact" )