Skip to main content

compute_cache_key

Function compute_cache_key 

Source
pub fn compute_cache_key(
    node_name: &str,
    input_state: &HashMap<String, Value>,
) -> String
Available on crate features graph and node-cache only.
Expand description

Computes a deterministic cache key from a node name and its input state.

The key is the hex-encoded blake3 hash of the node name concatenated with the canonical (sorted-key) JSON serialization of the input state.

§Arguments

  • node_name — the name of the graph node
  • input_state — the state map provided as input to the node

§Example

use adk_graph::cache::compute_cache_key;
use serde_json::json;
use std::collections::HashMap;

let mut state = HashMap::new();
state.insert("x".to_string(), json!(1));
state.insert("y".to_string(), json!(2));

let key = compute_cache_key("add", &state);
// key is a 64-character hex string (blake3 digest)
assert_eq!(key.len(), 64);

// Same inputs always produce the same key
let key2 = compute_cache_key("add", &state);
assert_eq!(key, key2);