gsh/runtime/store
The store module provides a lightweight, persistent key-value cache
backed by the Erlang Process Dictionary (erlang:get/1 and erlang:put/2).
In GSH’s synthetic runtime approach, generated evaluation modules re-declare historical statements to maintain lexical scope. To prevent duplicate side-effects (such as process spawning or network calls), every variable binding is wrapped in a cache lookup. This module ensures that bindings are computed exactly once during their initial evaluation and retrieved directly from BEAM process memory in subsequent prompts.
Values
pub fn cache(key: String, compute: fn() -> a) -> a
Evaluates a computation closure or retrieves its cached result from process memory.
Cache Logic:
- If
keyexists in the Erlang Process Dictionary, retrieves and returns the stored value immediately. - If
keyis absent, executes thecomputeclosure, caches the evaluated result underkey, and returns it.