Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow @Cacheable method to return java.util.Optional variant of cached value with @Cacheable(sync=true) [SPR-14853] #19419

spring-projects-issues opened this issue Oct 26, 2016 · 1 comment


Copy link

@spring-projects-issues spring-projects-issues commented Oct 26, 2016

Craig opened SPR-14853 and commented

#18804 is still reproducible if "sync=true" is set on the @Cacheable annotation.

For example, in

class MyServiceImpl implements MyService {

    private static final String CACHE_NAME = "itemCache";      

    @Cacheable(value=CACHE_NAME, sync=)
    public Optional<Item> findById(Long id) {
        // access the repository to retrieve the item

    @CachePut(cacheNames = CACHE_NAME, key = "")
    public Item insertItem(Item item) {


a ClassCastException is thrown.

The problem is in - when sync=true, a diffferent path is taken that does not do the Optional wrapping/unwrapping which takes place at

Affects: 4.3.3

Issue Links:

  • #18804 Allow @Cacheable method to return java.util.Optional variant of cached value

1 votes, 3 watchers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants