Docket.Postgres.GraphCache (docket v0.1.0)

Copy Markdown View Source

Optional node-local cache of compiled runtime graphs and known-incompatible graph versions.

Entries are keyed by the store namespace, graph owner scope, and store-provided {graph_id, graph_hash} and validated on every read against the local generation: a fingerprint of the :docket application's loaded modules plus the beam MD5 of each node implementation module recorded when the entry was written. An entry whose generation no longer matches is erased and reported as a miss, so a cached graph never crosses an incompatible local generation and cache loss only affects latency.

Incompatible entries record why a version cannot run here so repeated claims of the same doomed version skip the fetch and compile. A version whose stored document could not even be decoded records no module list; those entries additionally expire after :undecodable_ttl_ms so a deploy that only adds host modules still retries within one backoff window.

Terms live in :persistent_term: reads are copy-free, writes happen once per graph version per generation, and stale entries self-evict on read. Entries for graph versions that stop being claimed are not swept; clear/0 removes everything.

All functions accept the same options:

  • :generation - zero-arity function replacing the built-in :docket module fingerprint, for hosts that prefer an explicit release identity
  • :cache_scope - opaque storage namespace and graph owner identity; vehicles always provide this so tenant-specific corruption cannot poison another tenant's cache entry
  • :undecodable_ttl_ms - lifetime of entries recorded without a module list (default 30000)

Summary

Functions

Erases every cache entry.

Functions

clear()

@spec clear() :: :ok

Erases every cache entry.