QMD Cache¶
akms.graph.qmd_cache
¶
qmd_cache.py — QMD query cache layer (§2.6 of system design).
Caches qmd search results by (graph_version, query_hash). Cache is invalidated when graph_version changes.
Graph version = SHA256 of graph.json contents, minus the generated_at
timestamp, so recompiling identical inputs keeps the same version.
Query hash = SHA256 of (tags, role, depth) — see query_subgraph.compute_query_hash.
Cache storage:
compute_graph_version
¶
Compute the graph version: a SHA256 of graph.json's content.
The graph.generated_at timestamp is left out, so recompiling the same
inputs yields the same version (and the same resolution fingerprint). The
rest of the document is hashed as canonical JSON (sorted keys, compact
separators), so whitespace differences do not change the version either.
A file that is not a JSON object is hashed byte for byte.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_json_path
|
str | Path
|
Path to graph.json. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SHA256 hex digest, or |
Source code in packages/akms/src/akms/graph/qmd_cache.py
get_cached
¶
Retrieve cached query results if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
str | Path
|
Repository root path. |
required |
graph_version
|
str
|
SHA256 of current graph.json. |
required |
query_hash
|
str
|
SHA256 of query parameters. |
required |
Returns:
| Type | Description |
|---|---|
list | None
|
Cached result list, or None on cache miss. |
Source code in packages/akms/src/akms/graph/qmd_cache.py
put_cached
¶
Store query results in cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
repo_root
|
str | Path
|
Repository root path. |
required |
graph_version
|
str
|
SHA256 of current graph.json. |
required |
query_hash
|
str
|
SHA256 of query parameters. |
required |
results
|
list
|
The query results to cache (list of node_id strings). |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the cache file. |
Source code in packages/akms/src/akms/graph/qmd_cache.py
invalidate_cache
¶
Remove all cached entries.
Called when graph.json is rebuilt to avoid stale results.
Returns:
| Type | Description |
|---|---|
int
|
Number of cache files removed. |