cache

package
v1.0.0-alpha.4 Latest Latest
Warning

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

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

Documentation

Overview

Package cache provides opt-in memoization for materialize.Materialize.

The kernel deliberately holds no materialize cache (Principle I — the kernel stays stateless, and invalidation policy differs per consumer: the operator keys on a CR generation, the CLI opts out and relies on CUE's on-disk module cache). Consumers that want memoization construct a MaterializeCache themselves, derive a key with Key, and wrap their Materialize calls.

Unlike schema.Cache (a single-value sync.Once memo of the core schema), this is a multi-entry keyed cache — a different shape, hence a separate type.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(p *platform.Platform) (string, error)

Key derives a stable cache key from a platform's #registry subtree — the input that fully determines materialization (Q2: registry-only). The key is invariant to field ordering and to enable defaulting (an explicit `enable: true` hashes the same as the default), and to allow/deny list ordering, so two semantically-identical registries map to the same key.

The whole-spec alternative (hashing metadata too) was rejected: metadata does not affect the materialized transformer index, so keying on it would cause spurious cache misses on cosmetic edits.

Types

type LRU

type LRU struct {
	// contains filtered or unexported fields
}

LRU is the reference MaterializeCache: a fixed-capacity, least-recently- used cache safe for concurrent use. A non-positive capacity disables caching (Put is a no-op, Get always misses).

func NewLRU

func NewLRU(capacity int) *LRU

NewLRU returns an LRU holding at most capacity entries. A non-positive capacity yields a cache that never stores anything.

func (*LRU) Get

Get implements MaterializeCache.

func (*LRU) Put

func (c *LRU) Put(key string, mp *materialize.MaterializedPlatform)

Put implements MaterializeCache.

type MaterializeCache

type MaterializeCache interface {
	// Get returns the cached platform for key and whether it was present.
	Get(key string) (*materialize.MaterializedPlatform, bool)
	// Put stores mp under key, evicting per the implementation's policy.
	Put(key string, mp *materialize.MaterializedPlatform)
}

MaterializeCache memoizes materialized platforms by a caller-derived key (see Key). Implementations MUST be safe for concurrent use.

Jump to

Keyboard shortcuts

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