A batching, caching loader over key type K and value type V. batch_loadreceives the distinct, un-cached keys and must return their values positionally(result i is the value for key i). key derives a stable cache/identitystring for a key.
Run the pending batch: call batch_load once with the queued distinct keys,store each returned value in the cache under its key, and clear the queue. Ano-op when nothing is queued, so it is safe to call after every pass.
Queue k for the next dispatch. A key already cached or already queued inthis pass is dropped, so the batch that dispatch runs sees each distinct keyexactly once — this dedupe is what collapses N+1 into one call.