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. Query hash = SHA256 of (tags, role, depth) — see query_subgraph.compute_query_hash.
Cache storage:
compute_graph_version
¶
Compute SHA256 hash of graph.json as the graph version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph_json_path
|
str | Path
|
Path to graph.json. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SHA256 hex digest of the file contents. |
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. |