EmbedderCache class

The cached embedder, the rule for reusing it, and the serialisation that makes the rule mean anything.

Each of the three shells (mobile/desktop/web) used to hold this state as its own private fields and re-implement the decision over them. Three copies is three chances to get it wrong, and all three were wrong differently:

  • mobile compared the active spec's NAME, so a same-named embedder reinstalled to a new path was served stale; its explicit-paths entry returned the cached model with no comparison at all; and its reuse gate required a field that is only assigned AFTER the build returns, so a second caller arriving mid-build fell through and started a SECOND build, leaving the loser outside core's bookkeeping, so nothing in the plugin would ever close it.
  • desktop gated its comparison on that same after-the-build field and then joined any build in flight without comparing anything, so a caller asking for a different model file was handed the one already being built.
  • web was the strictest — it did compare resolved paths — but had no in-flight guard whatsoever, so two concurrent first callers each built their own model.

None of the three identity-guarded its close listener, so a late close of a superseded embedder evicted the live one. One object, one rule; the shells keep the wiring.

There is deliberately no Completer here. Its only job would be to let a concurrent caller join a build already in flight, which serialize makes impossible — and a completer that outlives its build is a hang waiting to happen: any throw between installing it and entering the enclosing try leaves every later caller awaiting something nobody will ever complete.

Constructors

EmbedderCache()

Properties

hashCode → int
The hash code for this object.
no setterinherited
model → EmbeddingModel?
The cached embedder, or null when none is built — or when the one that was built has been closed.
no setter
params → ActiveEmbedderParams?
What model was built from. Null exactly when model is null — closed included, so the two getters never describe different models.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

adopt(EmbeddingModel model, ActiveEmbedderParams params) → Future<void>
Records model, or closes it when the cache cannot take custody.
invalidate() → void
Forgets the cached embedder without closing it.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
record(EmbeddingModel model, ActiveEmbedderParams params) → void
Records a freshly built model and what it was built from.
reuseOrInvalidate(ActiveEmbedderParams requested, {required String label}) → Future<EmbeddingModel?>
The cached embedder when it matches requested, else null for "build one".
serialize<T>(Future<T> body()) → Future<T>
Runs body after every earlier serialize call on this cache has settled, so that resolving paths, deciding on reuse and building are one indivisible step.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited