rendercache

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

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

View Source
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.

View Source
const DefaultMaxSizeBytes int64 = 512 * 1024 * 1024

DefaultMaxSizeBytes is the default eviction cap: 512 MiB.

View Source
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

func DefaultDir() (string, error)

DefaultDir returns <os.UserCacheDir()>/drydock/render, consistent with the existing git/chart/remote cache roots.

func ModuleLabel

func ModuleLabel(info *debug.BuildInfo, modulePath string) string

ModuleLabel formats the version label for modulePath from build info, including any replace directive. Unknown modules return the bare path.

func ResolveDir

func ResolveDir(dir string, forbiddenRoots []string) (string, error)

ResolveDir resolves the configured render cache root and rejects locations inside repository roots or other protected roots.

func VCSCommitFromBuildInfo

func VCSCommitFromBuildInfo() (string, bool)

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

type EntryFile struct {
	Key        string
	Path       string
	SizeBytes  int64
	ModifiedAt time.Time
}

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.

func Entries

func Entries(dir string) ([]EntryFile, error)

Entries lists the persisted entries under dir without creating anything. A missing or empty store yields an empty result.

type EntryMeta

type EntryMeta struct {
	Version string
	Commit  string
}

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

func Open(dir string, maxSizeBytes int64) (*Store, error)

Open prepares the versioned cache root under dir. An empty dir uses DefaultDir; a non-positive maxSizeBytes uses DefaultMaxSizeBytes.

func (*Store) Delete

func (s *Store) Delete(key string) error

Delete removes the entry for key, tolerating a missing file.

func (*Store) Get

func (s *Store) Get(key string) ([]byte, bool, error)

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

func (s *Store) Put(key string, payload []byte, meta EntryMeta) error

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.

func (*Store) Writes

func (s *Store) Writes() int64

Writes reports how many entries this handle has written. The post-run eviction sweep only runs when at least one entry was written.

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.

func SweepDir

func SweepDir(dir string, maxSizeBytes int64) (SweepResult, error)

SweepDir enforces the size cap and removes stale orphaned temp files without creating the store. A non-positive maxSizeBytes uses the default cap. A missing store yields a zero result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL