Skip to content

Commit 8d1bf99

Browse files
committed
Cache the loaded handler
1 parent 0f1aff6 commit 8d1bf99

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

handler-loader/src/main/java/fr/axelop/agnosticserverlessfunctions/HandlerLoader.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
public class HandlerLoader {
77

88
private static final Class<Handler> HANDLER_CLASS = Handler.class;
9+
private static Optional<Handler> cached = Optional.empty();
910

1011
public Handler loadOrThrow() throws HandlerNotFoundException {
1112
return load().orElseThrow(HandlerNotFoundException::new);
1213
}
1314

1415
public Optional<Handler> load() {
15-
return ServiceLoader.load(HANDLER_CLASS).findFirst();
16+
cached = cached.or(ServiceLoader.load(HANDLER_CLASS)::findFirst);
17+
return cached;
1618
}
1719

1820
}

0 commit comments

Comments
 (0)