Skip to content

v0.9.0

Latest

Choose a tag to compare

@andared andared released this 14 Oct 11:03

Batch loading for views, iterators, and S3-FIFO

ViewOptions.BatchLoader and View.GetManyOrLoad. Views load many keys in one upstream call, by the caller's keys, with the cache's semantics: single flight and invalidation per key, GetOrLoad through the batch loader when there is no Loader, due keys refreshed in one call. ViewStats.Batches counts the calls.

Cache.All and View.All iterate over the cached values, for dumping a cache or warming another from it. The loop may use the cache; negative and expired entries are skipped, and nothing is counted or reordered.

S3FIFO, a new eviction policy: new entries wait in a small queue until they are read again, so keys read once leave before they push out the ones in steady use. Reads take only a read lock, as with ClearOnFull, and Set still always stores. In the comparison benchmarks, with 4096 entries against 100,000 keys on zipf s=1.01, it reaches 71.3% hits against 65.8% for LRU and 71.5% for otter, at 20 ns per read on eight cores.

A cache of any used through views needs no Cost under MaxBytes when every view brings one: NewView requires it then, and values written to the cache directly are charged as negative entries are.

Fixed: since 0.8.0, a failed load had its zero value passed to Cost, so a Cost that reads through a nil pointer turned the load's error into a panic.

Breaking: requires Go 1.25; New and NewView panic on a TTL, NegativeTTL or RefreshAfter shorter than ten ClockGranularity intervals; ViewStats gained Batches, so code that builds it positionally needs updating. See CHANGELOG.md.

Install:

go get github.com/andared/sanecache@v0.9.0