Even I faced the similar issue after using this it got fixed and required data is being stored in redis Cache only after satisfying condition (I need to store in the cache only if result is not null and and also success should not be false).
@Cacheable(value = "myBucketName", key = "#dto.mobNumber", unless = "(#result == null || #result.success == false)")
public SummaryDto getSummary(Dto dto) {
return repository.getSummary(dto);
}