Documentation
¶
Overview ¶
Package rendercache implements the persistent on-disk render-output cache store: content-addressed gzipped JSON envelopes with atomic writes and LRU-by-mtime size-cap eviction. The package stores opaque payload bytes and has no knowledge of internal/app types; the app layer marshals its own payload, so this package can be imported by internal/app without an import cycle.
Index ¶
- Constants
- func DefaultDir() (string, error)
- func ModuleLabel(info *debug.BuildInfo, modulePath string) string
- func ResolveDir(dir string, forbiddenRoots []string) (string, error)
- func VCSCommitFromBuildInfo() (string, bool)
- type EngineFingerprint
- type EntryFile
- type EntryMeta
- type Store
- type SweepResult
Constants ¶
const ( ArgoCDModulePath = "github.com/argoproj/argo-cd/v3" GitOpsEngineModulePath = "github.com/argoproj/argo-cd/gitops-engine" HelmModulePath = "helm.sh/helm/v4" KustomizeModulePath = "sigs.k8s.io/kustomize/api" JsonnetModulePath = "github.com/google/go-jsonnet" KubernetesModulePath = "k8s.io/apimachinery" )
Render-relevant engine module paths. These participate in the persistent key; cmd/drydock and the CLI version output alias them so there is exactly one list to extend when a new module starts affecting rendered output.
const DefaultMaxSizeBytes int64 = 512 * 1024 * 1024
DefaultMaxSizeBytes is the default eviction cap: 512 MiB.
const FormatVersion = 1
FormatVersion is the entry schema version. It rotates together with the "v1" path segment on any entry-schema change and participates in the persistent render cache key.
Variables ¶
This section is empty.
Functions ¶
func DefaultDir ¶
DefaultDir returns <os.UserCacheDir()>/drydock/render, consistent with the existing git/chart/remote cache roots.
func ModuleLabel ¶
ModuleLabel formats the version label for modulePath from build info, including any replace directive. Unknown modules return the bare path.
func ResolveDir ¶
ResolveDir resolves the configured render cache root and rejects locations inside repository roots or other protected roots.
func VCSCommitFromBuildInfo ¶
VCSCommitFromBuildInfo returns the embedded clean VCS revision, if any. A dirty worktree build returns ("", false) because it cannot prove its render code matches any cached entry.
Types ¶
type EngineFingerprint ¶
type EngineFingerprint struct {
Version string `json:"version"`
Commit string `json:"commit"`
ArgoCDModule string `json:"argoCDModule"`
GitOpsEngineModule string `json:"gitOpsEngineModule"`
HelmModule string `json:"helmModule"`
KustomizeModule string `json:"kustomizeModule"`
JsonnetModule string `json:"jsonnetModule"`
KubernetesModule string `json:"kubernetesModule"`
}
EngineFingerprint identifies the render code that produced or would consume a cache entry. All fields participate in the persistent key.
func FingerprintFromBuildInfo ¶
func FingerprintFromBuildInfo() EngineFingerprint
FingerprintFromBuildInfo derives a fingerprint from debug.ReadBuildInfo: module versions from Deps, commit from clean VCS stamping. pkg/drydock uses this so library consumers never supply the fingerprint themselves.
func (EngineFingerprint) Known ¶
func (f EngineFingerprint) Known() bool
Known reports whether the fingerprint can prove which render code built an entry. An un-ldflagged dev build ("none"/empty commit, no clean VCS buildinfo) cannot, so persistence is disabled for it.
type EntryFile ¶
EntryFile describes one persisted render cache entry on disk. Lifecycle listing is stat-only: reading version/commit metadata would require decompressing each entry, which cache commands must not pay.
type EntryMeta ¶
EntryMeta describes the drydock build that produced an entry. It is stored in the envelope for debuggability and never read back into results.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is a handle on one cache directory. It is safe for concurrent use; concurrent processes sharing the directory are safe by construction through atomic rename writes and ENOENT-tolerant deletes.
func Open ¶
Open prepares the versioned cache root under dir. An empty dir uses DefaultDir; a non-positive maxSizeBytes uses DefaultMaxSizeBytes.
func (*Store) Get ¶
Get returns the opaque payload for key. A missing entry is (nil, false, nil). A corrupt, unparseable, or wrong-key entry is deleted (ENOENT-tolerant) and reported as an error so callers can emit an error-action cache event and treat it as a miss. A hit refreshes the entry mtime best-effort for LRU eviction.
func (*Store) Put ¶
Put writes the entry atomically: serialize to a temp file in the destination directory, then rename. A lost write race with a concurrent process costs one redundant render; torn reads are avoided by never writing in place.
func (*Store) Sweep ¶
func (s *Store) Sweep() (SweepResult, error)
Sweep enforces the size cap. When the summed entry size exceeds the cap, it deletes oldest-mtime entries until at or below 90% of cap. Missing files are tolerated so concurrent sweeps and concurrent corrupt-entry deletes race benignly. Sweep also removes stale orphaned .put-* temp files regardless of the cap.
type SweepResult ¶
type SweepResult struct {
// TotalBytes is the post-sweep sum of entry sizes.
TotalBytes int64 `json:"totalBytes" yaml:"totalBytes"`
// EvictedBytes is the sum of deleted entry sizes.
EvictedBytes int64 `json:"evictedBytes" yaml:"evictedBytes"`
// EvictedKeys lists deleted entry keys in eviction order.
EvictedKeys []string `json:"evictedKeys" yaml:"evictedKeys"`
}
SweepResult reports what one eviction sweep did.