17#include <unordered_map>
19namespace neograph::graph {
47 std::function<std::string(
const RunContext&)> context_key;
92 std::optional<NodeResult>
lookup(
const std::string& node_name,
93 const std::string& state_hash)
const;
96 std::optional<NodeResult>
lookup(
const std::string& node_name,
97 const std::string& state_hash,
98 const std::string& scope_key)
const;
101 void store(
const std::string& node_name,
102 const std::string& state_hash,
106 void store(
const std::string& node_name,
107 const std::string& state_hash,
108 const std::string& scope_key,
135 std::uint64_t last_used = 0;
138 static std::string make_key(
const std::string& node_name,
139 const std::string& state_hash,
140 const std::string& scope_key);
141 void evict_one_locked();
143 mutable std::mutex mu_;
144 std::set<std::string> enabled_nodes_;
145 std::unordered_map<std::string, CacheKeyPolicy> policies_;
146 mutable std::unordered_map<std::string, CacheEntry> entries_;
147 mutable std::size_t hits_ = 0;
148 mutable std::size_t misses_ = 0;
149 std::size_t max_entries_ = 0;
150 std::size_t evictions_ = 0;
151 mutable std::uint64_t access_sequence_ = 0;
NEOGRAPH_API export/import macro for shared-library builds.
std::size_t max_entries() const
Configured global entry bound. Zero means unbounded.
void set_max_entries(std::size_t max_entries)
Set the global entry bound.
void store(const std::string &node_name, const std::string &state_hash, NodeResult result)
Store the NodeResult for this (node, state_hash).
std::optional< NodeResult > lookup(const std::string &node_name, const std::string &state_hash, const std::string &scope_key) const
Lookup with the execution or caller-declared reusable scope key.
std::optional< NodeResult > lookup(const std::string &node_name, const std::string &state_hash) const
Lookup. nullopt if no cached result for this (node, state_hash).
std::size_t eviction_count() const
Lifetime capacity-eviction count. clear() and overwrite do not count.
void set_enabled(const std::string &node_name, bool enabled)
Enable / disable caching for a specific node.
std::size_t miss_count() const
Lifetime miss count (incremented on lookup that returns nullopt for an enabled node).
void store(const std::string &node_name, const std::string &state_hash, const std::string &scope_key, NodeResult result)
Store with the execution or caller-declared reusable scope key.
std::size_t hit_count() const
Lifetime hit count (incremented on lookup that returns a value).
CacheKeyPolicy policy_for(const std::string &node_name) const
Return a node's policy, or the safe execution-local default.
bool is_enabled(const std::string &node_name) const
True iff set_enabled(node_name, true) was the last call for it.
void set_policy(const std::string &node_name, CacheKeyPolicy policy)
Set a node's cache identity policy. The default is execution-local.
void clear()
Drop all cached entries (per-node enable/disable state preserved).
std::size_t size() const
Number of entries currently held.
Graph engine type definitions: channels, edges, nodes, events, and control flow.
NEOGRAPH_API std::string hash_state_for_cache(const json &state_value)
Stable hash over the JSON state used as the cache-key suffix.
CacheScope
Lifetime boundary for a cached node result.
Explicit cache identity policy for one node.
Extended result returned by node execution.
Per-run dispatch metadata threaded through the engine and executor.