lru icon indicating copy to clipboard operation
lru copied to clipboard

GetOrLoad has a strange `ok` return value

Open judofyr opened this issue 10 months ago • 0 comments

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 shared flag 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:

  1. Loader invoked => This request had to wait for the loader.
  2. Loader not invoked + shared: false => This request was served fully from the cache.
  3. Loader not invoked + shared: true => This request had to wait in the queue.

judofyr avatar Apr 10 '25 09:04 judofyr