Skip to content

v0.7.0

Choose a tag to compare

@andared andared released this 30 Sep 10:16
· 19 commits to main since this release

Loads that need more than the key, and load errors that are errors

Cache.GetOrLoadFunc and View.GetOrLoadFunc take the loader with the call. A loader in Options sees only the key, so an upstream call that needs a query string, a header or a request the caller has already built had to be encoded into the key and parsed back out. Everything else is GetOrLoad's: single flight, storage with the cache's or view's cost and TTLs, ErrNotFound as a negative entry, the error, cancellation and panic policies. Loads are shared with GetOrLoad and GetManyOrLoad of the same key, so callers of one key wait for whichever load started first, and the function must return what any other caller's would for that key. Neither Options.Loader nor ViewOptions.Loader is needed for it.

LoadErrors no longer counts ErrNotFound. "Does not exist" is an answer, and counting it as a failure made a service asking for ids that are gone look broken on every dashboard built on LoadErrors. Those loads are counted in the new Stats.LoadNotFound and ViewStats.LoadNotFound, keys missing from a BatchLoader answer included. LoadErrors + LoadNotFound is what LoadErrors used to report.

See CHANGELOG.md for migration notes.

Install:

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