I always solved it as follows.
interface KeyValueService<K,V> { V get(K key); } class CachingKeyValueService<K,V> { Cache<K,Optional<V>> cache; V get(K key) { return cache.get(key).orNull(); } }
Ideally, you should change the interface for KeyValueService to always return optional, but sometimes this is not possible.
You can use weighting to quickly remove all optional links. ABSENT.
source share