# `RpcLoadBalancer.LoadBalancer.NodeCpuCache`
[🔗](https://github.com/MikaAK/rpc_load_balancer/blob/main/lib/rpc_load_balancer/load_balancer/node_cpu_cache.ex#L1)

Shared ETS cache for CPU metrics, keyed by node.

CPU utilization is a property of the node itself, not of any
particular load balancer — every load balancer that contains a given
node sees the same value. Storing one entry per node (rather than
per `{load_balancer_name, target_node}`) deduplicates writes,
simplifies the cache shape, and lets every Poller across every load
balancer cooperate on warming the same data.

Backed by `Cache.PersistentTerm` so the read path on every selection
is a single `:persistent_term.get/2`. Writes (one per Poller tick)
trigger a global GC sweep, but pollers run on the order of seconds
and selection runs millions of times per second — the asymmetry is
the right shape for `:persistent_term`. Test sandboxing flows
through `Cache.SandboxRegistry`.

# `entry`

```elixir
@type entry() :: %{cpu: float(), fetched_at: integer()}
```

# `adapter_options`

# `cache_adapter`

# `cache_name`

# `child_spec`

# `delete`

# `delete_cpu`

```elixir
@spec delete_cpu(node()) :: :ok | {:error, ErrorMessage.t()}
```

# `get`

# `get_cpu`

```elixir
@spec get_cpu(node()) :: entry() | nil
```

Read a node's cached CPU entry without telemetry overhead.

Calls the configured cache adapter directly so per-node reads inside
`LeastCpu.choose_from_nodes/3` don't pay `:telemetry.span/3` overhead
for every node in the cluster. Returns `nil` when no entry exists,
letting the caller fall back to a default.

# `get_local_cpu`

```elixir
@spec get_local_cpu() :: entry() | nil
```

Reads the local node's cached CPU entry.

Exposed as a zero-arity function so `:erpc.multicall/5` can target it
with an empty argument list — the remote node resolves its own
identity rather than the caller embedding it in the key.

# `get_or_create`

# `put`

# `put_cpu`

```elixir
@spec put_cpu(node(), entry()) :: :ok | {:error, ErrorMessage.t()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
