Skip to main content

EvalCache

Struct EvalCache 

Source
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: u64

Monotonically 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

Source

pub fn new() -> Self

Source

pub fn clear(&mut self)

Source

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.

Source

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).

Source

pub fn needs_full_evaluation(&self) -> bool

Returns true if evaluate_internal must run (versions changed since last full evaluation)

Source

pub fn mark_evaluated(&mut self)

Call after evaluate_internal completes successfully to mark the generation stable

Source

pub fn set_active_item(&mut self, idx: usize)

Source

pub fn clear_active_item(&mut self)

Source

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.

Source

pub fn get_active_snapshot(&self) -> Value

Source

pub fn diff_active_item( &mut self, field_key: &str, old_sub_data: &Value, new_sub_data: &Value, )

Source

pub fn bump_data_version(&mut self, data_path: &str)

Source

pub fn bump_params_version(&mut self, data_path: &str)

Source

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)
Source

pub fn check_table_cache( &self, eval_key: &str, deps: &IndexSet<String>, ) -> Option<Value>

Specialized cache check for $params-scoped table evaluations.

Tables in $params/references/ aggregate cross-item data and produce a single result that is independent of which subform item is currently active. The standard check_cache blocks T2 reuse for entries whose deps include non-$params paths (e.g. /riders/...), because scalar formula results are item-specific. But table results are global: the same 734-row array is correct for rider 0, rider 1, and rider 2 alike.

This method validates the global entry directly — using item_data_versions for non-$params deps — without the index_safe gate, allowing the expensive table forward/ backward pass to be skipped when inputs have not changed.

Source

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.entries is written only from the main form (no active item). Subforms can reuse these via the Tier 2 fallback in check_cache.

Trait Implementations§

Source§

impl Clone for EvalCache

Source§

fn clone(&self) -> EvalCache

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for EvalCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.