Repository navigation
v0.6.0
Loading many keys in one upstream call
Options.BatchLoader and Cache.GetManyOrLoad. Keys a batch does not find in the cache go to the upstream in one call instead of one call per key. Single flight, invalidation and cancellation work key by key: batches and GetOrLoad calls that overlap share loads rather than repeating them, and a caller who gives up on part of a batch does not cancel it for someone waiting on another part. A requested key missing from the loader's answer is cached as "does not exist"; an error fails the whole call, and nothing from that call is cached.
One loader is enough. GetOrLoad falls back to BatchLoader with a batch of one when Loader is not set, and GetManyOrLoad falls back to concurrent Loader calls when BatchLoader is not set.
Counters. Stats.Batches counts BatchLoader calls. Stats.Loads and Stats.LoadErrors now count keys rather than loader calls, which keeps Coalesced comparable with Loads; for Loader alone nothing changes. The text of ErrNoLoader names Options.BatchLoader too; compare with errors.Is, not with the string.
Views have no batch loading yet; ViewOptions is unchanged.
See CHANGELOG.md for migration notes.
Install:
go get github.com/andared/sanecache@v0.6.0