lru
lru copied to clipboard
GetOrLoad has a strange `ok` return value
GetOrLoad returns (value V, err error, ok bool), but the ok parameter is a bit strange:
- If the value was in cache then it's always
true. - If the value wasn't in cache then it returns the
sharedflag from the single flight group.
I'm not really sure what I'm supposed to do with this return value. I think it would be more valuable for the return value to be (value V, err error, shared bool) and then return false here if it was in the cache. That makes it possible for me to detect three different scenarios:
- Loader invoked => This request had to wait for the loader.
- Loader not invoked +
shared: false=> This request was served fully from the cache. - Loader not invoked +
shared: true=> This request had to wait in the queue.