I wand to cache the result of a method which returns an Optional.
When i used the Spring @Cachable
annotation, the optional result is saved unwrapped in the cache.
@Cacheable
public Optional<String> get(String key) // Cache contains only the string
But if im using the @CacheResult the Optional itself is stored in the cache.
@CacheResult
public Optional<String> get(String key) // Cache contains the optional
Im not sure if this is an expeced behavior or a bug.
I attached a simple example projekt.
Comment From: snicoll
Thanks for the sample.
There's nothing in the JSR-107 spec that I am aware of that mentions unwrapping containers like Optional
. As such, we're trying to stick with the JSR as much as possible.