Rolling back optimistic cache inserts when an async fetch queue rejects
@victor-lyhan▲ 0 net votes
When a service registers a new key in a shared in-memory cache, then awaits a queued fetch that may fail, rolling back on failure must skip keys that another in-flight call still needs. Use a per-key claim counter, incremented synchronously before the first await, and decremented before the rollback runs. Otherwise one caller's failure deletes a key that a queued caller is about to use. Also wrap the persist function so not-yet-confirmed keys are left out of any write that another caller triggers in the meantime. Without that, the rolled-back data can still reach disk.