Why Cache Validity Needs an Explicit Rule
A cached imputation result can save substantial computation, but reuse is safe only when it still answers the current computational request. A dataset may be edited, a missing-value code may be reinterpreted, a predictor may be added to a conditional model, or a preprocessing script may change. If the cache check overlooks a relevant change, downstream analysis can silently use an output from a different workflow. Conversely, invalidating every result after any edit wastes computation and makes a workflow harder to maintain.
The central task is therefore to state which inputs determine a particular cached artifact, record those inputs or reliable identifiers for them, and compare them with the current request before reuse. A cache check is a software control, not evidence that an imputation model is statistically appropriate. The earlier material on preserving raw data and tracking provenance, modular scripts, configuration files, deterministic preprocessing, and serialized MICE results supplies useful workflow practices; here the focus is the decision to reuse or recompute.
Define What the Cache Represents
Begin by naming the artifact being cached. An imputation run object, completed datasets, pooled estimates, and a formatted report are different artifacts with different dependencies. For example, a change to a table's label may require rebuilding the report but not rerunning imputation. A change to the imputation model or the data ordinarily requires recomputing the imputation artifact and any downstream artifact that depends on it.
A useful formal representation is a dependency tuple \(D=(D_{\text{data}},D_{\text{schema}},D_{\text{preprocess}},D_{\text{method}},D_{\text{settings}},D_{\text{code}},D_{\text{software}},D_{\text{random}})\). The terms stand for the data values and row/column identity; variable types and missing-value encodings; preprocessing; imputation methods and predictor structure; run settings; relevant implementation code; relevant software versions; and random-number controls. The tuple should be adapted to the artifact: a report may also depend on analysis code, formatting settings, and the saved analysis results.
Some dependencies need more detail than a label. For example, the method component may need the method assigned to each variable, the predictor matrix, visit sequence, number of imputations, and iteration settings. Randomness may depend on the seed, random-number generator, stream allocation, and parallel execution choices. A software component should identify versions that can affect the output, including relevant packages and custom routines. Do not include every machine detail automatically; record what is needed to distinguish executions that could yield materially different artifacts.
Fingerprints, Equality, and the Collision Caveat
A workflow may compare full dependency records directly, or it may compute fingerprints (often called hashes) from canonical representations of those records. A cache key can be written as \(K=H(C(D))\), where \(C\) converts the dependency tuple into a stable representation and \(H\) maps that representation to a fixed-length value. Canonicalization matters: equivalent settings must be serialized consistently, and meaningful distinctions—such as a variable's type or a missing-value code—must not be discarded.
A hash is useful for efficient lookup, but it is not a logically perfect identity test. Different inputs can produce the same fingerprint, and distinct component fingerprints can in turn produce the same overall key. Thus, a changed input does not guarantee that its fingerprint or the overall cache key changes. A cryptographic hash can make accidental collisions extremely unlikely in ordinary practice, but “unlikely” is not “impossible.” If a mismatch must be logically established, compare the recorded dependency values directly, or state that the conclusion relies on an assumption of collision-free fingerprints. A robust practical system can use fingerprints for lookup and then compare the canonical dependency records before reuse.
Worked Example: One Edited Value in the Input Data
Suppose a hypothetical MICE input has 120 patients and variables for age, treatment group, and a laboratory measurement. A cached run was created when patient 17's laboratory value was 10. The current input has that value recorded as 30; all other listed settings are unchanged. Should the old imputation result be reused?
The data dependency values differ: \(D_{\text{data,new}}\ne D_{\text{data,old}}\), because at least one recorded value differs. This directly establishes a dependency mismatch without making any claim about hash behavior. Reuse is not justified for an artifact whose imputation depends on that input table. The imputation should be recomputed, along with downstream results that depend on it.
A system that uses fingerprints will ordinarily produce different data fingerprints and cache keys for these inputs, subject to collision risk. It is incorrect to claim that the fingerprint or key must differ: a hash function need not be injective. If the system needs a logically certain mismatch decision, it can compare the canonical data records or use an explicit versioned data identity whose update rule is controlled and verified.
A Safe Reuse Decision
The decision has two parts. First establish that the requested artifact has the same complete dependency values as the cached artifact under the declared comparison rule. Then establish that the computation is sufficiently controlled for the intended notion of reuse. If the goal is to reproduce the same stochastic realization, random-number settings and relevant execution behavior must be part of the dependency specification. If the goal is only to accept an already computed valid realization, the workflow may permit reuse under a different rule, but it must say so rather than silently treating it as the same run.
The reasoning behind this rule can be stated precisely. Suppose the computation producing artifact \(A\) is a function \(A=F(D)\), where \(D\) contains every dependency and execution is deterministic once \(D\) is fixed. If the current and recorded dependency tuples are equal, then both calls evaluate the same function at the same input, so their outputs agree: \(F(D_{\text{current}})=F(D_{\text{recorded}})\). This justification fails if an input is omitted, if execution has uncontrolled randomness, or if apparently identical records are interpreted differently by the software. It also does not mean that a hash-key match proves tuple equality; that implication would require an injective key function or direct verification.
Specify whether the cache contains an imputation run, completed data, pooled analysis, or a report. List the direct dependencies of that object.
Save enough data, configuration, code, software, and random-control information to identify the request that generated the artifact.
Check the manifest against the current request. Use fingerprints for efficient lookup, but compare canonical records when certainty about equality is required.
Reuse only when all relevant dependencies match and the declared execution assumptions hold. Otherwise recompute this artifact and its dependent outputs, not unrelated upstream or downstream objects.
Worked Example: A Change to a Report Label
A hypothetical workflow caches completed imputations for 120 patients and separately caches a report table. The analyst changes the displayed label “Group B” to “Treatment B.” The raw data, variable coding, imputation methods, model settings, code that creates imputations, and software are unchanged. The report-generation template is changed.
For the imputation artifact, compare its dependency tuple: none of the listed imputation dependencies changed. Under the stated assumption that the label edit affects only presentation and not the variable values or model code, the completed imputations remain eligible for reuse. The report artifact has a changed direct dependency—its template—so the report should be regenerated from the saved results. This is selective invalidation: rerunning MICE would not be required by this particular edit.
The conclusion depends on verifying that “label” really is presentation-only. If the edit also changes a category value used in the data or a mapping used in preprocessing, then the imputation dependency values may differ and imputation should be recomputed. A change's filename or description is not enough; inspect what it changes in the dependency graph.
Worked Example: Changed Seed and Imputation Settings
A hypothetical run uses \(m=5\) imputations, 20 iterations, seed 4102, and a fixed random-number generator. A second request keeps the data, method, and software unchanged but sets \(m=10\) and seed 4103. Determine whether the first cached output answers the second request.
The settings differ because \(10\ne5\), and the recorded seed values differ because \(4103\ne4102\). Therefore the dependency tuples are not equal. The old cache does not represent the requested run: it contains five imputations rather than ten, and it was generated under a different random-number control. Recompute for the new request. Again, this conclusion follows from direct comparison of the recorded values; it does not require asserting that hash fingerprints or keys must differ.
If only the seed changed while \(m=5\) remained fixed, whether to recompute would depend on the cache's purpose. To reproduce the specifically requested random realization, a changed seed requires recomputation. If the objective is merely to reuse a previously generated set of five imputations for an analysis that accepts any valid realization, that may be allowed by a separately declared policy—but it is not an exact match to the new run specification.
Diagnostics and Common Failure Modes
A cache policy should make mismatches visible rather than returning only “hit” or “miss.” Record which dependency fields were compared and identify any mismatch or missing field. A small manifest table can help distinguish a changed data version from a changed method setting or software version. This supports troubleshooting without substituting for the workflow's broader audit record.
- Stale reuse: a variable dictionary, missing-value encoding, predictor structure, preprocessing rule, or custom function changed but was not included in the manifest. The cache appears to match while representing an older request.
- Unstable representation: the same configuration is serialized in different orders or formats, causing unnecessary misses. Canonicalize representations before fingerprinting.
- Overly broad invalidation: a report-label edit invalidates an imputation object even though it is not a dependency. Separate cache layers by artifact and dependency.
- Uncontrolled randomness: a seed is recorded but parallel stream allocation or generator behavior is not controlled. Identical seed text alone may not reproduce identical output.
- Hash-only confidence: a matching fingerprint is treated as proof of identical inputs. It is evidence under a collision-risk assumption, not a mathematical guarantee; compare stored dependency records when exact equality matters.
- Missing manifest: an old serialized result has no trustworthy record of how it was made. Do not infer the missing dependencies from the result alone; rerun under the current specification if safe reuse cannot be established.
Checksums are particularly useful for detecting accidental changes to files, but their interpretation still depends on how files are read and represented. For instance, a file fingerprint can change because of harmless formatting, or remain an incomplete description if an input is loaded from an unrecorded external source. A cache manifest should describe the actual computational inputs after relevant decoding and preprocessing, not only the name of a source file.
Alternatives and Limits
Three common strategies have different trade-offs. Comparing full dependency records is transparent and can establish equality of the recorded values, but may require storage and comparison effort. Fingerprint-based lookup is compact and fast, but relies on a collision-risk assumption unless followed by direct comparison. Manual invalidation—deleting caches whenever a person suspects a change—is simple for tiny workflows but is prone to both stale reuse and unnecessary recomputation. A dependency graph with separate artifacts is often a practical compromise: each object is invalidated when one of its direct dependencies changes, and invalidation propagates to objects that depend on it.
No strategy can safely validate a cache if the manifest omits a dependency or if the computation has untracked external inputs. Also, matching inputs does not certify convergence, model adequacy, or the substantive validity of an imputation. Those are separate statistical and computational checks. Cache validity means only that the stored artifact corresponds to the specified computation under the declared assumptions.
Check Your Understanding
Answer each question, then compare with the brief solutions.
- A categorical missing-value code is changed from “?” to “NA” in a preprocessing rule, but the raw file is unchanged. Which dependency should be checked, and is the old imputation cache automatically safe to reuse?
- Explain why different dependency values do not logically guarantee different hash fingerprints.
- A report font changes, while imputation inputs and analysis results are unchanged. Which artifact should ordinarily be rebuilt?
- A cached result has a matching key, but its manifest did not record the predictor matrix. What is the safe decision?
- A seed changes, but all other run settings are fixed. When does the change require recomputation?
Solutions. (1) Check preprocessing and missing-value encoding, which affect how the input is interpreted. The old cache is not automatically safe; recompute if the interpreted data or imputation request differs. (2) A hash maps an input space to a finite set of outputs, so it need not be one-to-one; distinct inputs can collide. (3) Rebuild the report, not ordinarily the imputations, assuming the font change is presentation-only. (4) Safe reuse has not been established because a potentially relevant dependency is unknown; recover and compare the predictor matrix or recompute. (5) Recompute when the requested output must correspond to the new seed or reproduce that random realization. Reuse under a different policy is possible only if the goal permits any acceptable realization and that policy is explicit.