Closed
Description
Acacio Antonio Andruczewicz opened SPR-14230 and commented
class MyServiceImpl implements MyService {
private static final String CACHE_NAME = "itemCache";
@Override
@Cacheable(CACHE_NAME)
public Optional<Item> findById(Long id) {
// access the repository to retrieve the item
}
@Override
@CachePut(cacheNames = CACHE_NAME, key = "#item.id")
public Item insertItem(Item item) {
...
}
}
In the above example, a ClassCastException is thrown because insertItem puts an Item instance in the cache, and findById expects an Optional that may contain an Item instance. It would be nice if Spring cache abstraction supported Java 8 Optional.
Affects: 4.2.5
Reference URL: http://stackoverflow.com/questions/36844270/handling-java-8-optional-with-spring-cache
Issue Links:
- Provide means to configure multithreaded access for cache abstraction [SPR-9254] #13892 Provide means to configure multithreaded access for cache abstraction
- Using Spring beans as a part of key in cache annotations (@Cacheable etc.) doesn't work [SPR-9578] #14212 Using Spring beans as a part of key in cache annotations (
@Cacheable
etc.) doesn't work - Allow @Cacheable method to return java.util.Optional variant of cached value with @Cacheable(sync=true) [SPR-14853] #19419 Allow
@Cacheable
method to return java.util.Optional variant of cached value with@Cacheable
(sync=true) - Allow @CachePut to specify the object to store using SpEL [SPR-14341] #18913 Allow
@CachePut
to specify the object to store using SpEL
Referenced from: commits 240f254, fdb31cd
0 votes, 5 watchers