diff --git a/Source/JNA/waffle-jna-jakarta/src/main/java/waffle/util/cache/Cache.java b/Source/JNA/waffle-jna-jakarta/src/main/java/waffle/util/cache/Cache.java index 523ed97a38..9d977ef53e 100644 --- a/Source/JNA/waffle-jna-jakarta/src/main/java/waffle/util/cache/Cache.java +++ b/Source/JNA/waffle-jna-jakarta/src/main/java/waffle/util/cache/Cache.java @@ -26,6 +26,9 @@ import java.util.NoSuchElementException; import java.util.ServiceLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * A semi-persistent mapping from keys to values. * @@ -60,13 +63,22 @@ public interface Cache { */ static Cache newCache(int timeout) throws NoSuchElementException { final NoSuchElementException exception = new NoSuchElementException(); + boolean cacheSupplierFound = false; for (CacheSupplier cacheSupplier : ServiceLoader.load(CacheSupplier.class)) { + cacheSupplierFound = true; try { return cacheSupplier.newCache(timeout); } catch (Exception e) { exception.addSuppressed(e); } } + + if (!cacheSupplierFound) { + Logger logger = LoggerFactory.getLogger(Cache.class); + logger.error("No CacheSupplier implementation found by ServiceLoader. Please see https://github.com/Waffle/waffle/blob/master/Docs/faq/CustomCache.md for possible solutions. Falling back to default CaffeineCache implementation.", exception); + return new CaffeineCache<>(timeout); + } + throw exception; } diff --git a/Source/JNA/waffle-jna/src/main/java/waffle/util/cache/Cache.java b/Source/JNA/waffle-jna/src/main/java/waffle/util/cache/Cache.java index da45192ba7..02c2a966ce 100644 --- a/Source/JNA/waffle-jna/src/main/java/waffle/util/cache/Cache.java +++ b/Source/JNA/waffle-jna/src/main/java/waffle/util/cache/Cache.java @@ -26,6 +26,9 @@ import java.util.NoSuchElementException; import java.util.ServiceLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * A semi-persistent mapping from keys to values. * @@ -60,13 +63,22 @@ public interface Cache { */ static Cache newCache(int timeout) throws NoSuchElementException { final NoSuchElementException exception = new NoSuchElementException(); + boolean cacheSupplierFound = false; for (CacheSupplier cacheSupplier : ServiceLoader.load(CacheSupplier.class)) { + cacheSupplierFound = true; try { return cacheSupplier.newCache(timeout); } catch (Exception e) { exception.addSuppressed(e); } } + + if (!cacheSupplierFound) { + Logger logger = LoggerFactory.getLogger(Cache.class); + logger.error("No CacheSupplier implementation found by ServiceLoader. Please see https://github.com/Waffle/waffle/blob/master/Docs/faq/CustomCache.md for possible solutions. Falling back to default CaffeineCache implementation.", exception); + return new CaffeineCache<>(timeout); + } + throw exception; }