Documentation
¶
Overview ¶
Package cache acquires verified source bytes into immutable memory or OCI-backed filesystems.
Index ¶
- Constants
- Variables
- func AcquisitionIdentity(input any) string
- func CredentialsUnavailable(err error) bool
- func FileName(input fs.FS) string
- func MachineCredentialErr(cause error) error
- func NameBlob(name string, generation fs.FS) fs.FS
- func RecordInventory[T io.WriterTo](ctx context.Context, c *Cache, inventory AcceptedInventory[T]) error
- func RenderPersistenceDisabledReason() string
- func StagedCaptureAnnotation(purpose string) string
- type AcceptedInventory
- type ArchiveKey
- type BlobKey
- type Cache
- func (c *Cache) Acquire(ctx context.Context, key ArchiveKey, policyValue *Policy, ...) (fs.FS, ocispec.Descriptor, string, error)
- func (c *Cache) Blob(ctx context.Context, key BlobKey, policyValue *Policy, ...) (fs.FS, ocispec.Descriptor, string, error)
- func (c *Cache) CanPersistRenders() bool
- func (c *Cache) Close() error
- func (c *Cache) Compose(ctx context.Context, request Composition, policyValue *Policy) (fs.FS, ocispec.Descriptor, string, error)
- func (c *Cache) Directory() string
- func (c *Cache) Git(ctx context.Context, key GitKey, policyValue *Policy, ops GitOperations) (*GitGeneration, string, error)
- func (c *Cache) ProducersForPaths(ctx context.Context, query []manifest.SourceEvidence) (map[manifest.NamedResource][]manifest.SourceEvidence, error)
- func (c *Cache) RecordRender(ctx context.Context, acceptance RenderAcceptance) error
- type Composition
- type CompositionInput
- type Copy
- type CopyMode
- type Error
- type Frame
- func (f *Frame) ContentIdentity() string
- func (f *Frame) History(owner manifest.NamedResource, content any) (iter.Seq2[manifest.NamedResource, manifest.DiscoveryRecord], bool)
- func (f *Frame) Payload(ctx context.Context) ([]byte, error)
- func (f *Frame) PreparePublication(ctx context.Context, input FramePublicationInput) (*FramePublication, error)
- func (f *Frame) ReadPayload(ctx context.Context, offset int64, size int) ([]byte, error)
- type FramePublication
- type FramePublicationInput
- type GitGeneration
- type GitKey
- type GitOperations
- type Policy
- type ProducerInput
- type ProducerResult
- type RenderAcceptance
- type RenderBinding
- type RenderCheck
- type RenderDomain
- func (d *RenderDomain[P, H]) Read(ctx context.Context, generation fs.FS) (RenderReceipt[P, H], bool, error)
- func (d *RenderDomain[P, H]) Receipt(f RenderReceipt[P, H]) *manifest.RenderReceipt
- func (d *RenderDomain[P, H]) Validate(ctx context.Context, f *RenderReceipt[P, H], inputs *RenderBinding[P], ...) (RenderValidation, error)
- func (d *RenderDomain[P, H]) WritePending(ctx context.Context, w io.Writer, f *RenderReceipt[P, H]) error
- type RenderFrame
- type RenderHistory
- type RenderLookups
- type RenderMode
- type RenderPublication
- type RenderReceipt
- type RenderValidation
- type RetryConfig
- type StagedCapture
- type SweepOpts
- type SweepResult
- type TerminalError
Constants ¶
const Forever time.Duration = -1
Forever retains a successfully resolved pin regardless of elapsed time.
Variables ¶
var ErrRestartGit = errors.New("restart Git acquisition")
ErrRestartGit discards one unpublished generation before retry classification.
Functions ¶
func AcquisitionIdentity ¶
AcquisitionIdentity reports the held generation and shaping of cache-owned filesystems. Anonymous inputs and wrappers have no acquisition authority.
func CredentialsUnavailable ¶
CredentialsUnavailable leaves cancellation precedence and retry decisions to the caller.
func MachineCredentialErr ¶
MachineCredentialErr masks machine diagnostics while preserving typed causes.
func RecordInventory ¶
func RecordInventory[T io.WriterTo](ctx context.Context, c *Cache, inventory AcceptedInventory[T]) error
RecordInventory atomically replaces accepted content and its searchable provenance.
func RenderPersistenceDisabledReason ¶
func RenderPersistenceDisabledReason() string
RenderPersistenceDisabledReason returns why this binary cannot persist renders, or an empty string when it can.
func StagedCaptureAnnotation ¶ added in v0.8.1
StagedCaptureAnnotation identifies a captured value in the composition descriptor.
Types ¶
type AcceptedInventory ¶
type AcceptedInventory[T io.WriterTo] struct { Key, Lookup, Acceptance string History RenderHistory Content T Work *manifest.AcquisitionWork }
AcceptedInventory publishes one complete inventory and its source evidence.
type ArchiveKey ¶
type ArchiveKey struct {
// Content describes the producer inputs.
Content any
Ignore string
Policy string
// Required lists unprefixed descriptor annotation names; it does not affect identity.
Required []string
}
ArchiveKey identifies an archive and its source-ignore policy. Content MUST include the effective credentials used by the producer.
type BlobKey ¶
type BlobKey struct {
// Content describes the producer inputs, or a nonempty identity for rendered content.
Content any
// Render selects pending work or accepted history; zero denotes source content.
Render RenderMode
// Lookups belongs to one renderer preparation and must not be shared across concurrent calls.
Lookups *RenderLookups
// Validate checks a candidate against this caller's inputs under the acquisition lock.
// Streams belong to the callback; the callback never affects identity.
Validate func(context.Context, fs.FS) (bool, error)
// Observe receives the validated candidate or nil before production, once per call.
// Returning true completes this call without producing or publishing a generation.
Observe func(context.Context, fs.FS) (bool, error)
// Required lists unprefixed descriptor annotation names; it does not affect identity.
Required []string
}
BlobKey identifies single-file content. Content MUST include the effective credentials used by the producer.
func InputFrameLookup ¶ added in v0.8.1
InputFrameLookup identifies saved loader state for the source origin and URL.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache owns acquired generations until Close. Readers MUST finish before Close.
func (*Cache) Acquire ¶
func (c *Cache) Acquire( ctx context.Context, key ArchiveKey, policyValue *Policy, produce func(context.Context, ProducerInput) (ProducerResult, error), ) (fs.FS, ocispec.Descriptor, string, error)
Acquire publishes a complete archive or revalidates its previous generation after produce succeeds. Its acquisition identity is empty on failure.
func (*Cache) Blob ¶
func (c *Cache) Blob( ctx context.Context, key BlobKey, policyValue *Policy, produce func(context.Context, ProducerInput) (ProducerResult, error), ) (fs.FS, ocispec.Descriptor, string, error)
Blob returns an immutable filesystem over a complete generation. A nil producer only looks up a fresh generation; zero Policy.MaxAge with a producer replaces the generation. Unchanged production retains the previous payload and replaces its upstream metadata. A successful generation rejected by Validate is returned once without being retained for reuse. Its acquisition identity is empty on failure.
func (*Cache) CanPersistRenders ¶
CanPersistRenders reports whether the cache owner can persist accepted renders.
func (*Cache) Compose ¶
func (c *Cache) Compose( ctx context.Context, request Composition, policyValue *Policy, ) (fs.FS, ocispec.Descriptor, string, error)
Compose borrows input filesystems until production returns. Output backing belongs to the cache.
func (*Cache) Directory ¶
Directory returns the resolved disk boundary, or empty for a memory owner.
func (*Cache) Git ¶
func (c *Cache) Git( ctx context.Context, key GitKey, policyValue *Policy, ops GitOperations, ) (*GitGeneration, string, error)
Git acquires an immutable generation through the common freshness and publication path. Its acquisition identity is empty on failure.
func (*Cache) ProducersForPaths ¶
func (c *Cache) ProducersForPaths( ctx context.Context, query []manifest.SourceEvidence, ) (map[manifest.NamedResource][]manifest.SourceEvidence, error)
ProducersForPaths returns producers whose accepted source paths reach the supplied changes. The result is positive admission evidence, never proof that an inventory remains complete.
func (*Cache) RecordRender ¶
func (c *Cache) RecordRender(ctx context.Context, acceptance RenderAcceptance) error
RecordRender MUST publish accepted frames and searchable source evidence together.
type Composition ¶
type Composition struct {
Base CompositionInput
Inputs []CompositionInput
Copies []Copy
Policy string
Ignore string
Captures []StagedCapture
}
Composition MUST identify the complete base and ordered operations before cache reuse.
type CompositionInput ¶
type CompositionInput struct {
FS fs.FS
Alias string
// Empty Content forces fresh production because the backing can change.
Content string
// Backing distinguishes mutable inputs that can coexist under the same recipe.
Backing string
}
CompositionInput MUST identify immutable backing or force fresh production.
type Copy ¶
Copy paths MUST use secure resolution for PlaceTree and relative archive paths otherwise.
type Error ¶
type Error struct{ Err error }
Error MUST retain manifest.ErrFlux and the underlying cause.
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame retains immutable metadata and the acquired generation, never a mutable lookup. It MUST NOT be copied after payload access.
func (*Frame) ContentIdentity ¶ added in v0.8.1
ContentIdentity identifies the certified frame contents before acceptance.
func (*Frame) History ¶
func (f *Frame) History( owner manifest.NamedResource, content any, ) (iter.Seq2[manifest.NamedResource, manifest.DiscoveryRecord], bool)
History requires current final content before it supplies accepted records.
func (*Frame) Payload ¶
Payload returns immutable bytes after validating the complete payload identity.
func (*Frame) PreparePublication ¶
func (f *Frame) PreparePublication(ctx context.Context, input FramePublicationInput) (*FramePublication, error)
PreparePublication returns no publication when complete evidence cannot be fingerprinted or encoded within the limit.
type FramePublication ¶
type FramePublication struct {
// contains filtered or unexported fields
}
FramePublication keeps prepared bytes and identities immutable across concurrent callers.
func (*FramePublication) Frame ¶
func (p *FramePublication) Frame() *Frame
Frame exposes the prepared snapshot without changing the original acceptance.
func (*FramePublication) Identity ¶
func (p *FramePublication) Identity() string
Identity binds deduplication to the complete prepared publication.
type FramePublicationInput ¶
type FramePublicationInput struct {
Owner manifest.NamedResource
Content any
Records iter.Seq2[manifest.NamedResource, manifest.DiscoveryRecord]
Complete bool
}
FramePublicationInput MUST describe the accepted output under Owner.
type GitGeneration ¶
type GitGeneration struct {
Backing billy.Filesystem
Worktree billy.Filesystem
Commit plumbing.Hash
// contains filtered or unexported fields
}
GitGeneration retains sealed object backing and any upstream recursive checkout. Every reader MUST construct its own storer; publication retains no producer handles.
type GitKey ¶
GitKey identifies a Git family, its normalized requested ref and recursion policy. Content MUST include the effective credentials used by the producer.
type GitOperations ¶ added in v0.8.1
type GitOperations struct {
Fetch func(context.Context, storage.Storer, billy.Filesystem) (plumbing.Hash, error)
List func(context.Context) plumbing.Hash
Validate func(ctx context.Context, generation *GitGeneration, checkObjects bool) error
}
GitOperations supplies the remote operations and validates the retained backing before publication.
type Policy ¶
type Policy struct {
// Work borrows counters owned by this acquisition caller.
Work *manifest.AcquisitionWork
// HistoryWork borrows separate cells for accepted render history.
HistoryWork *manifest.AcquisitionWork
// Admit runs before each production attempt's timeout and staged storage.
// Success MUST return a non-nil release, called once after cleanup/publication.
// On error the callback owns partial cleanup; cache failures do not retry or persist outcomes.
Admit func(context.Context) (func(), error)
// Timeout bounds each production attempt; nil adds no deadline.
Timeout *time.Duration
// MaxAge bounds freshness; Forever retains immutable pins.
MaxAge time.Duration
// Retry applies only to producer failures.
Retry RetryConfig
}
Policy is the caller's immutable freshness, retry, admission and operation timeout policy.
type ProducerInput ¶
ProducerInput writes new content or exposes the owner's last complete generation.
func (ProducerInput) Previous ¶
func (p ProducerInput) Previous(ctx context.Context) (*ocispec.Descriptor, error)
Previous returns independent upstream metadata, or nil when no usable payload exists. It retains no open reader and MUST only be called during production.
func (ProducerInput) Work ¶
func (p ProducerInput) Work() *manifest.AcquisitionWork
Work returns the physical acquisition counters borrowed from the caller.
type ProducerResult ¶
type ProducerResult struct {
ocispec.Descriptor
// Unchanged requires a usable previous payload and forbids writing new bytes.
Unchanged bool
}
ProducerResult reports new bytes or successful validation of the previous payload.
type RenderAcceptance ¶
type RenderAcceptance struct {
Owner manifest.NamedResource
Receipt *manifest.RenderReceipt
Records iter.Seq2[manifest.NamedResource, manifest.DiscoveryRecord]
Sources []manifest.SourceEvidence
Content any
Work *manifest.RenderWork
Source manifest.SourceIdentity
Reads *store.ReadSet
OutputReads *store.ReadSet
}
RenderAcceptance MUST retain complete emission evidence and live captures through publication.
type RenderBinding ¶
type RenderBinding[P any] struct { Key string `json:"Key"` Source manifest.NamedResource `json:"Source"` Artifact store.ArtifactHistory `json:"Artifact"` Policy P `json:"Policy"` }
RenderBinding MUST keep raw render identity separate from the acquisition family.
func (*RenderBinding[P]) Equal ¶
func (b *RenderBinding[P]) Equal(other *RenderBinding[P], equalPolicy func(P, P) bool) bool
Equal MUST compare typed policy without hashing or reflection.
func (*RenderBinding[P]) Fingerprint ¶
func (b *RenderBinding[P]) Fingerprint() string
Fingerprint MUST derive history identity within the cache owner.
func (*RenderBinding[P]) Refresh ¶
func (b *RenderBinding[P]) Refresh(key string, source manifest.NamedResource, artifact *store.SourceArtifact)
Refresh MUST preserve retained policy slices and earlier request snapshots.
type RenderCheck ¶ added in v0.8.1
RenderCheck supplies domain evidence. A history check MUST NOT acquire remote inputs.
type RenderDomain ¶ added in v0.8.1
type RenderDomain[P, H any] struct { Name string EqualPolicy func(P, P) bool ValidHeader func(H) bool EqualHeader func(H, H) bool Prepare func(H) H Accept func(H, *RenderAcceptance) (any, []manifest.SourceEvidence) // contains filtered or unexported fields }
RenderDomain supplies the policy and metadata rules for one render format.
func NewRenderDomain ¶ added in v0.8.1
func NewRenderDomain[P, H any](domain RenderDomain[P, H]) *RenderDomain[P, H]
NewRenderDomain MUST run once per domain so receipts share the comparator.
func (*RenderDomain[P, H]) Read ¶ added in v0.8.1
func (d *RenderDomain[P, H]) Read(ctx context.Context, generation fs.FS) (RenderReceipt[P, H], bool, error)
func (*RenderDomain[P, H]) Receipt ¶ added in v0.8.1
func (d *RenderDomain[P, H]) Receipt(f RenderReceipt[P, H]) *manifest.RenderReceipt
Receipt preserves the caller's snapshot for comparison and publication.
func (*RenderDomain[P, H]) Validate ¶ added in v0.8.1
func (d *RenderDomain[P, H]) Validate( ctx context.Context, f *RenderReceipt[P, H], inputs *RenderBinding[P], check RenderCheck[H], ) (RenderValidation, error)
Validate applies the same eligibility rules to fresh and retained generations. A history probe MUST reject a different binding before it consults domain evidence.
func (*RenderDomain[P, H]) WritePending ¶ added in v0.8.1
func (d *RenderDomain[P, H]) WritePending(ctx context.Context, w io.Writer, f *RenderReceipt[P, H]) error
WritePending stores raw output without granting ownership or acceptance.
type RenderFrame ¶
type RenderFrame struct {
Key string
// Lookup addresses accepted storage and MUST NOT confer acceptance by itself.
Lookup string
Binding string
Output []byte
Stored *Frame
}
RenderFrame MUST retain Frame by pointer because Frame contains atomic state.
func OpenRenderFrame ¶
func OpenRenderFrame(ctx context.Context, domain string, generation fs.FS, metadata any) (RenderFrame, error)
OpenRenderFrame MUST preserve storage error classification while hydrating reusable output.
func (*RenderFrame) Encode ¶
func (f *RenderFrame) Encode(domain string, metadata any) (*Frame, error)
Encode MUST reuse immutable stored envelopes until the binding changes.
func (*RenderFrame) History ¶ added in v0.8.1
func (f *RenderFrame) History( owner manifest.NamedResource, content any, ) (iter.Seq2[manifest.NamedResource, manifest.DiscoveryRecord], bool)
History requires a bound frame and complete inventory for the current content.
func (*RenderFrame) Rebind ¶
func (f *RenderFrame) Rebind(binding string)
Rebind MUST operate on a renderer's copied frame to preserve previous receipts.
type RenderHistory ¶
type RenderHistory struct {
Owner manifest.NamedResource `json:"Owner"`
Sources []manifest.SourceEvidence
}
RenderHistory supplies source paths associated with one accepted inventory.
type RenderLookups ¶ added in v0.8.1
type RenderLookups struct {
// contains filtered or unexported fields
}
RenderLookups retains cache identities within one renderer preparation.
func (*RenderLookups) Accepted ¶ added in v0.8.1
func (l *RenderLookups) Accepted(content string) string
Accepted returns the cache identity already prepared for publication.
type RenderMode ¶
type RenderMode uint8
RenderMode identifies the acquisition phase of rendered content.
const ( // RenderPending validates accepted history, then coalesces immutable work until Close. RenderPending RenderMode = iota + 1 // RenderAccepted persists only complete accepted render history with identified backing. RenderAccepted )
type RenderPublication ¶
type RenderPublication struct {
Frame RenderFrame
Domain string
Metadata any
Content any
Sources []manifest.SourceEvidence
}
RenderPublication MUST project engine metadata without publishing or encoding it.
type RenderReceipt ¶ added in v0.8.1
type RenderReceipt[P, H any] struct { RenderFrame Inputs RenderBinding[P] Header H // contains filtered or unexported fields }
RenderReceipt retains immutable output and the domain's acceptance evidence.
func (RenderReceipt[P, H]) RenderPublication ¶ added in v0.8.1
func (f RenderReceipt[P, H]) RenderPublication(_ context.Context, a *RenderAcceptance) (RenderPublication, error)
RenderPublication prepares acceptance from a copy of the immutable receipt.
type RenderValidation ¶ added in v0.8.1
type RenderValidation struct {
Documents []manifest.DocOccurrence
Valid bool
Rebound bool
}
RenderValidation distinguishes a cache miss from a valid empty render.
type RetryConfig ¶
type RetryConfig struct {
// Attempts includes the first try; values <= 1 disable retries.
Attempts int
// MinWait defaults to 750 milliseconds when nonpositive.
MinWait time.Duration
// MaxWait defaults to 15 minutes when nonpositive.
MaxWait time.Duration
// Jitter is a fraction in [0,1]; non-finite values disable jitter.
Jitter float64
}
RetryConfig bounds producer attempts within one acquisition.
type StagedCapture ¶ added in v0.8.1
type StagedCapture struct {
Purpose string
Path string
Read func(context.Context, string, fs.FS) (string, error) `json:"-"`
}
StagedCapture keys a bounded read from the unfiltered tree by purpose and path.
type SweepOpts ¶
type SweepOpts struct {
// MaxAge retires named tags whose payload mtime predates now-MaxAge.
// Coalesced access timestamps allow one second of retention grace.
// Zero disables age retirement; unreachable Git generations are always collected.
MaxAge time.Duration
// DryRun reports the selection without locking or changing the cache.
DryRun bool
}
SweepOpts tunes Sweep's behavior.
type SweepResult ¶
type SweepResult struct {
// Removed lists selected tags and absolute Git-generation paths, sorted together.
Removed []string
// Bytes counts selected Git-generation bytes only. Upstream graph GC decides
// blob reclamation; dry-run does not estimate reclaimed blob bytes.
Bytes int64
// Errors aggregates failures applying the selection.
Errors []error
}
SweepResult summarizes Sweep's selection and any failures applying it.
type TerminalError ¶
type TerminalError struct {
// Err retains the typed cause and its diagnostic text.
Err error
// Attempted distinguishes producer exhaustion from a suppressed non-attempt.
Attempted bool
}
TerminalError prevents an outer acquisition from repeating a completed sequence.
func (*TerminalError) Error ¶
func (e *TerminalError) Error() string
Error preserves the underlying diagnostic.
func (*TerminalError) Unwrap ¶
func (e *TerminalError) Unwrap() []error
Unwrap exposes the domain sentinel and the underlying cause.