@@ -611,19 +611,22 @@ private Stream<ApplicationModule> allModules() {
611
611
* @param key must not be {@literal null}.
612
612
* @return will never be {@literal null}.
613
613
*/
614
- private static ApplicationModules of (CacheKey key ) {
614
+ private static ApplicationModules of (CacheKey cacheKey ) {
615
615
616
- Assert .notNull (key , "Cache key must not be null!" );
616
+ Assert .notNull (cacheKey , "Cache key must not be null!" );
617
617
618
- var metadata = key .getMetadata ();
619
- var modules = new ApplicationModules (metadata , key .getIgnored (),
620
- metadata .useFullyQualifiedModuleNames (), key .getOptions ());
618
+ return CACHE .computeIfAbsent (cacheKey , key -> {
621
619
622
- var sharedModules = metadata . getSharedModuleNames () //
623
- . map ( modules :: getRequiredModule ) //
624
- . collect ( Collectors . toSet ());
620
+ var metadata = key . getMetadata ();
621
+ var modules = new ApplicationModules ( metadata , key . getIgnored (),
622
+ metadata . useFullyQualifiedModuleNames (), key . getOptions ());
625
623
626
- return modules .withSharedModules (sharedModules );
624
+ var sharedModules = metadata .getSharedModuleNames () //
625
+ .map (modules ::getRequiredModule ) //
626
+ .collect (Collectors .toSet ());
627
+
628
+ return modules .withSharedModules (sharedModules );
629
+ });
627
630
}
628
631
629
632
/**
@@ -667,21 +670,24 @@ private static class CacheKey {
667
670
668
671
private final DescribedPredicate <JavaClass > ignored ;
669
672
private final ImportOption options ;
673
+ private final Object metadataSource ;
670
674
private final Supplier <ModulithMetadata > metadata ;
671
675
672
- public CacheKey (DescribedPredicate <JavaClass > ignored , ImportOption options , Supplier <ModulithMetadata > metadata ) {
676
+ public CacheKey (DescribedPredicate <JavaClass > ignored , ImportOption options , Object metadataSource ,
677
+ Supplier <ModulithMetadata > metadata ) {
673
678
674
679
this .ignored = ignored ;
675
680
this .options = options ;
681
+ this .metadataSource = metadataSource ;
676
682
this .metadata = SingletonSupplier .of (metadata );
677
683
}
678
684
679
685
static CacheKey of (String pkg , DescribedPredicate <JavaClass > ignored , ImportOption options ) {
680
- return new CacheKey (ignored , options , () -> ModulithMetadata .of (pkg ));
686
+ return new CacheKey (ignored , options , pkg , () -> ModulithMetadata .of (pkg ));
681
687
}
682
688
683
689
static CacheKey of (Class <?> type , DescribedPredicate <JavaClass > ignored , ImportOption options ) {
684
- return new CacheKey (ignored , options , () -> ModulithMetadata .of (type ));
690
+ return new CacheKey (ignored , options , type , () -> ModulithMetadata .of (type ));
685
691
}
686
692
687
693
DescribedPredicate <JavaClass > getIgnored () {
@@ -713,7 +719,16 @@ public boolean equals(Object obj) {
713
719
714
720
return Objects .equals (this .ignored , that .ignored )
715
721
&& Objects .equals (this .options , that .options )
716
- && Objects .equals (this .metadata .get (), that .metadata .get ());
722
+ && Objects .equals (this .metadataSource , that .metadataSource );
723
+ }
724
+
725
+ /*
726
+ * (non-Javadoc)
727
+ * @see java.lang.Object#hashCode()
728
+ */
729
+ @ Override
730
+ public int hashCode () {
731
+ return Objects .hash (ignored , options , metadataSource );
717
732
}
718
733
}
719
734
0 commit comments