3535 */
3636public final class PrioritizedComponents <T > {
3737 /**
38- * Reuses or creates and stores (if session data does not contain yet) prioritized components under certain key into
39- * given session. Same session is used to configure prioritized components, so priority sorted components during
40- * session are immutable and reusable.
38+ * Reuses or creates and caches (if session is equipped with cache, and it does not contain it yet)
39+ * prioritized components under certain key into session cache. Same session is used to configure prioritized
40+ * components, so priority sorted components during session are immutable and reusable (if {@code components}
41+ * component map is unchanged).
4142 * <p>
42- * The {@code components} are expected to be Sisu injected {@link Map<String, C> }-like component maps. There is a
43+ * The {@code components} are expected to be Sisu injected {@link Map}-like dynamic component maps. There is a
4344 * simple "change detection" in place, as injected maps are dynamic, they are atomically expanded or contracted
4445 * as components are dynamically discovered or unloaded.
4546 *
@@ -53,10 +54,11 @@ public static <C> PrioritizedComponents<C> reuseOrCreate(
5354 Function <C , Float > priorityFunction ) {
5455 boolean cached = ConfigUtils .getBoolean (
5556 session , ConfigurationProperties .DEFAULT_CACHED_PRIORITIES , ConfigurationProperties .CACHED_PRIORITIES );
56- if (cached ) {
57- String key = PrioritizedComponents .class .getName () + ".pc." + discriminator .getName ();
58- return (PrioritizedComponents <C >)
59- session .getData ().computeIfAbsent (key , () -> create (session , components , priorityFunction ));
57+ if (cached && session .getCache () != null ) {
58+ String key = PrioritizedComponents .class .getName () + ".pc." + discriminator .getName ()
59+ + Integer .toHexString (components .hashCode ());
60+ return (PrioritizedComponents <C >) session .getCache ()
61+ .computeIfAbsent (session , key , () -> create (session , components , priorityFunction ));
6062 } else {
6163 return create (session , components , priorityFunction );
6264 }
0 commit comments