Exception when one key has no value in Cache.getAll
See original GitHub issueCache
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:
- Created 6 years ago
- Comments:9 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.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?