Class DefaultLazyLoader<S,D>

java.lang.Object
org.keycloak.models.cache.infinispan.DefaultLazyLoader<S,D>
All Implemented Interfaces:
LazyLoader<S,D>

public class DefaultLazyLoader<S,D> extends Object implements LazyLoader<S,D>
Default implementation of LazyLoader that lazily loads and caches data. Data loaded from a source rejected by the configured cacheability predicate is returned without being cached, so a subsequent invocation attempts to load the data again. This implementation is thread-safe as cached data is used in instances of CachedRealm which are shared between multiple threads within a Keycloak instance.
Author:
Pedro Igor
  • Constructor Details

    • DefaultLazyLoader

      public DefaultLazyLoader(Function<S,D> loader, Supplier<D> fallback)
    • DefaultLazyLoader

      public DefaultLazyLoader(Function<S,D> loader, Supplier<D> fallback, Predicate<S> cacheable)
      Creates a loader that caches loaded data only when cacheable accepts its source.
      Parameters:
      loader - function used to load data from a non-null source
      fallback - supplier used when the source is null
      cacheable - predicate evaluated against a non-null source after its data has been loaded. If it returns false, the loaded data is returned without being cached and a subsequent invocation attempts to load again. When the source is null, the predicate is not evaluated and the fallback result is stored instead.
  • Method Details

    • get

      public D get(KeycloakSession session, Supplier<S> sourceSupplier)
      Description copied from interface: LazyLoader
      Returns data from the given source. Data is only fetched from source once and only if necessary, it is up to implementations to decide the momentum to actually fetch data from source.
      Specified by:
      get in interface LazyLoader<S,D>
      Parameters:
      session - the session
      sourceSupplier - the source from where data will be fetched.
      Returns:
      the data from source