Skip to content

Allow @Cacheable method to return CompletableFuture<java.util.Optional> variant of cached value #37162

Description

@jakoubektom
class MyService {

    @Cacheable("myCache")
    public CompletableFuture<Optional<String>> doSomethingExpensive(String id) {
        return CompletableFuture.completedFuture(Optional.ofNullable(id).map(i -> "PREFIX-" + i));
    }

}

In the above example, a ClassCastException is thrown when doSomethingExpensive is called a second time to retrieve the cached value but the cache actually returns CompletableFuture<String> instead of expected CompletableFuture<Optional<String>>.

Both CompletableFuture and Optional are currently supported separately, it would be nice to have support for their combination.

spring version: 7.0.8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions