pub struct EvalCache {
pub data_versions: VersionTracker,
pub params_versions: VersionTracker,
pub entries: HashMap<String, CacheEntry>,
pub active_item_index: Option<usize>,
pub subform_caches: HashMap<usize, SubformItemCache>,
pub eval_generation: u64,
pub last_evaluated_generation: u64,
pub main_form_snapshot: Option<Value>,
}Expand description
Primary cache structure for a JSON evaluation instance
Fields§
§data_versions: VersionTracker§params_versions: VersionTracker§entries: HashMap<String, CacheEntry>§active_item_index: Option<usize>§subform_caches: HashMap<usize, SubformItemCache>§eval_generation: u64Monotonically increasing counter bumped whenever data_versions or params_versions change.
When eval_generation == last_evaluated_generation, all cache entries are guaranteed valid
and evaluate_internal can skip the full tree traversal.
last_evaluated_generation: u64§main_form_snapshot: Option<Value>Snapshot of the last fully-diffed main-form data payload.
Stored after each successful evaluate_internal_with_new_data call so the next
invocation can avoid an extra snapshot_data_clone() when computing the diff.
Implementations§
Source§impl EvalCache
impl EvalCache
pub fn new() -> Self
pub fn clear(&mut self)
Sourcepub fn prune_subform_caches(&mut self, current_count: usize)
pub fn prune_subform_caches(&mut self, current_count: usize)
Remove item caches for indices >= current_count.
Call this whenever the subform array length is known to have shrunk so that
stale per-item version trackers and cached entries do not linger in memory.
Sourcepub fn invalidate_params_tables_for_item(
&mut self,
idx: usize,
table_keys: &[String],
)
pub fn invalidate_params_tables_for_item( &mut self, idx: usize, table_keys: &[String], )
Invalidate all $params-scoped table cache entries for a specific item.
Called when a brand-new subform item is introduced so that $params tables
that aggregate array data (e.g. WOP_RIDERS) are forced to recompute instead
of returning stale results cached from a prior main-form evaluation that ran
when the item was absent (and thus saw zero/null for that item’s values).
Sourcepub fn needs_full_evaluation(&self) -> bool
pub fn needs_full_evaluation(&self) -> bool
Returns true if evaluate_internal must run (versions changed since last full evaluation)
Sourcepub fn mark_evaluated(&mut self)
pub fn mark_evaluated(&mut self)
Call after evaluate_internal completes successfully to mark the generation stable
pub fn set_active_item(&mut self, idx: usize)
pub fn clear_active_item(&mut self)
Sourcepub fn store_snapshot_and_diff_versions(&mut self, old: &Value, new: &Value)
pub fn store_snapshot_and_diff_versions(&mut self, old: &Value, new: &Value)
Recursively diffs old against new and bumps version for every changed data path scalar.
pub fn get_active_snapshot(&self) -> Value
pub fn diff_active_item( &mut self, field_key: &str, old_sub_data: &Value, new_sub_data: &Value, )
pub fn bump_data_version(&mut self, data_path: &str)
pub fn bump_params_version(&mut self, data_path: &str)
Sourcepub fn check_cache(
&self,
eval_key: &str,
deps: &IndexSet<String>,
) -> Option<Value>
pub fn check_cache( &self, eval_key: &str, deps: &IndexSet<String>, ) -> Option<Value>
Check if the eval_key result can be safely bypassed because dependencies are unchanged.
Two-tier lookup:
- Tier 1: item-scoped entries in
subform_caches[idx]— checked first when an active item is set - Tier 2: global
self.entries— allows Run 1 (main form) results to be reused in Run 2 (subform)
Sourcepub fn store_cache(
&mut self,
eval_key: &str,
deps: &IndexSet<String>,
result: Value,
)
pub fn store_cache( &mut self, eval_key: &str, deps: &IndexSet<String>, result: Value, )
Store the newly evaluated value and snapshot the dependency versions.
Storage strategy:
- When an active item is set, store into
subform_caches[idx].entries(item-scoped). This isolates per-rider results so different items with different data don’t collide. - The global
self.entriesis written only from the main form (no active item). Subforms can reuse these via the Tier 2 fallback incheck_cache.