LangEx.Graph.NodeCache (LangEx v0.11.3)

Copy Markdown View Source

ETS-backed memoization for node results (the cache: node option).

Entries are keyed by {node_name, input_state_hash} and carry the full input term plus an expiry deadline. The stored input is compared on lookup, so a hash collision misses instead of serving a wrong result. Expired entries are deleted when read.

The table is created by the application supervisor and shared across all graphs in the VM. Its size is bounded by the :node_cache_max_entries application env (default 10000): when full, expired entries are purged first and, if still full, the whole table is flushed — a coarse but predictable eviction that keeps memory bounded.

Summary

Functions

Removes all cached node results.

Looks up a cached, unexpired node result whose input matches exactly.

Stores a node result with the given TTL in milliseconds (or :infinity).

Functions

clear()

@spec clear() :: :ok

Removes all cached node results.

fetch(key, input)

@spec fetch(term(), term()) :: {:ok, term()} | :miss

Looks up a cached, unexpired node result whose input matches exactly.

store(key, input, result, ttl)

@spec store(term(), term(), term(), timeout()) :: :ok

Stores a node result with the given TTL in milliseconds (or :infinity).