Module: lib/compiler/atlas/cache

Reusing per-unit Atlas fragments across rebuilds.

avenx serve and avenx watch rebuild the whole project on every save, and a project's components mostly do not change between two saves. This cache keeps the nodes and edges each component produced so an unchanged file is merged back rather than re-analysed.

What the key has to cover

A component's own text is not enough. Its edges resolve cart.total against the bridge's declared surface, so renaming a getter must invalidate every consumer's fragment even though none of their files changed. The key is therefore the file's content plus a digest of the surfaces it resolves against.

A stale fragment is worse than no cache — it would answer an impact query with relationships that no longer exist — so the key covers everything the fragment was derived from, and nothing is keyed on mtime or path alone.

The cache lives in memory for the life of the process. It is deliberately not on disk: the build is not incremental anywhere else, so a disk cache would add invalidation risk across process boundaries for a slice of a cost that is already small.

Source:

Members

(inner, constant) MAX_ENTRIES :number

How many unit fragments to retain.

Large enough for a substantial application, bounded so a long-lived dev server cannot grow without limit.

Type:
  • number
Source:

(inner, constant) store :Map:.<string:, object:>

Type:
  • Map:.<string:, object:>
Source:

Methods

(static) addCachedComponentUnit(model, unit) → {Object}

Adds a unit to the model, reusing a previous analysis when nothing it depends on has changed.

On a miss the unit is analysed into an isolated fragment model, which is built leniently — a component legitimately names bridge nodes it does not itself declare — and then merged into the real model under its normal edge rules.

Parameters:
Name Type Description
model AppModel

The model being built.

unit object

The unit, as addComponentUnit expects it.

Source:
Returns:

What was added, and whether it came from the cache.

Type
Object

(static) atlasCacheSize() → {number}

How many fragments are currently retained.

Source:
Returns:

The entry count.

Type
number

(static) cacheKey(unit) → {string}

Computes the cache key for a unit.

Parameters:
Name Type Description
unit object

The unit being analysed.

Source:
Returns:

The key.

Type
string

(static) clearAtlasCache() → {void}

Empties the cache.

Used by tests, and available to any caller that wants a guaranteed cold analysis.

Source:
Returns:
Type
void

(inner) surfaceDigest(bindings, bridges) → {string}

Digests the surfaces a unit's analysis depends on.

Only the parts a consumer can resolve against are included: a bridge's internals can change freely without altering what its consumers' edges mean.

Parameters:
Name Type Description
bindings Array:.<object:>

The unit's bridge bindings.

bridges Map:.<string:, object:>

Every bridge descriptor.

Source:
Returns:

A digest, stable across runs.

Type
string