> -      if (image == null)
> -         throwNoSuchElementExceptionAfterLoggingImageIds(format("%s not 
> found", idPredicate), images);
> -      return image;
> +      // Try find the image in the cache and fallback to the GetImageStrategy
> +      // see https://issues.apache.org/jira/browse/JCLOUDS-570
> +      Optional<? extends Image> image = tryFind(images, idPredicate);
> +      if (!image.isPresent()) {
> +         logger.warn("Image %s not found in the image cache. Trying to get 
> it directly...", imageId);
> +         // Note that this might generate make a call to the provider 
> instead of using a cache, but
> +         // this will be executed rarely, only when an image is not present 
> in the image list but
> +         // it actually exists in the provider. It shouldn't be an expensive 
> call so using a cache just for
> +         // this corner case is overkill.
> +         image = Optional.fromNullable(getImageStrategy.getImage(imageId));
> +         if (!image.isPresent()) {
> +            throwNoSuchElementExceptionAfterLoggingImageIds(format("%s not 
> found", idPredicate), images);
> +         }

[minor] We can save a bit of object construction at the cost of a little more 
complexity:
```
ImageThing imageFromProvider = getImageStrategy.getImage(imageId);
if (imageFromProvider == null) {
   ...
}
image = Optional.of(imageFromProvider); // or just return imageFromProvider
```
What do you think?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/396/files#r13522288

Reply via email to