Skip to main content

put_if_unchanged

Function put_if_unchanged 

Source
async fn put_if_unchanged(
    cache: &Cache<(OffchainPublicKey, OffchainPublicKey, u32), Arc<(u64, WeightedCollection<ValidatedPath>)>>,
    key: (OffchainPublicKey, OffchainPublicKey, u32),
    swept: &Arc<(u64, WeightedCollection<ValidatedPath>)>,
    value: Arc<(u64, WeightedCollection<ValidatedPath>)>,
) -> bool
Expand description

Writes value under key only if swept is still the entry cached there, returning whether it was.

The background refresh reads an entry, rebuilds it from the graph across awaits, then writes. A PathPlanner::recompute_paths_from that ran in between built from newer SURB evidence, so the refresh’s older selection must not land on top of it. The check and the write are one and_compute_with, which moka serialises against every other compute call on the key, and the recompute writes through one too — a plain insert would otherwise slip between this read and write. A key that went vacant meanwhile is left to the next fill.