question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Exception when one key has no value in Cache.getAll

See original GitHub issue

Cache interface was designed to throw an exception in the case of null or empty values. While this seems a reasonable behavior for Cache.get, I didn’t figured out how to deal when calling Cache.getAll.

I/O is expensive, so I collect all data I need at once using Cache.getAll. In the case that at least one key has no value, it throws an exception, which does not allow me to access the other valid values.

I found to options: first, using Cache.get instead of Cache.getAll; second, including null values as Optional. Both options are terrible considering performance. Is there a recommended solution to deal with this scenario? Otherwise, if possible, how could I help to improve the Cache API in this issue?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ben-manescommented, Aug 4, 2017

@Maaartinus That could have a race due to an eviction, for whatever reason. It tiny improvement would be to throw a custom exception with the results and then use cache.putAll to insert them. Then the results would be cached and the found set returned.

1reaction
lowassercommented, Aug 3, 2017

I’m not sure why you consider Optional “terrible considering performance.” Relative to almost any I/O operation, I’d expect the boxing incurred by Optional is going to be relatively minor. I’d expect that to be the appropriate solution in most cases.

Do you have performance data – perhaps from CacheStats – suggesting otherwise?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid caching when values are null? - Stack Overflow
Just throw some Exception if user is not found and catch it in client code while using get(key) method. new CacheLoader<ObjectId, User>() ...
Read more >
javax.cache.Cache.getAll java code examples - Tabnine
If the cache is configured read-through, and a get for a key would return null because an entry is missing from the cache,...
Read more >
Interface Cache<K,V> - Javadoc.io
Gets a collection of entries from the Cache , returning them as Map of the values associated with the set of keys requested....
Read more >
pub.cache:getAll - Software AG Documentation
If the key does not exist in the cache, pub.cache:getAll returns a null in the value parameter. If useLoader is set to true...
Read more >
About caching exceptions | cruftex.net
The cache is configured with a data source and calls it in case ... Should getAll() throw an exception or return only the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found