Class CachingAuthenticator<C,​P extends Principal>

  • Type Parameters:
    C - the type of credentials the authenticator can authenticate
    P - the type of principals the authenticator returns
    All Implemented Interfaces:
    Authenticator<C,​P>

    public class CachingAuthenticator<C,​P extends Principal>
    extends Object
    implements Authenticator<C,​P>
    An Authenticator decorator which uses a Caffeine cache to temporarily cache credentials and their corresponding principals.
    • Constructor Detail

      • CachingAuthenticator

        public CachingAuthenticator​(com.codahale.metrics.MetricRegistry metricRegistry,
                                    Authenticator<C,​P> authenticator,
                                    com.github.benmanes.caffeine.cache.CaffeineSpec cacheSpec)
        Creates a new cached authenticator.
        Parameters:
        metricRegistry - the application's registry of metrics
        authenticator - the underlying authenticator
        cacheSpec - a CaffeineSpec
      • CachingAuthenticator

        public CachingAuthenticator​(com.codahale.metrics.MetricRegistry metricRegistry,
                                    Authenticator<C,​P> authenticator,
                                    com.github.benmanes.caffeine.cache.Caffeine<Object,​Object> builder)
        Creates a new cached authenticator.
        Parameters:
        metricRegistry - the application's registry of metrics
        authenticator - the underlying authenticator
        builder - a Caffeine
    • Method Detail

      • invalidate

        public void invalidate​(C credentials)
        Discards any cached principal for the given credentials.
        Parameters:
        credentials - a set of credentials
      • invalidateAll

        public void invalidateAll​(Iterable<C> credentials)
        Discards any cached principal for the given collection of credentials.
        Parameters:
        credentials - a collection of credentials
      • invalidateAll

        public void invalidateAll​(Predicate<? super C> predicate)
        Discards any cached principal for the collection of credentials satisfying the given predicate.
        Parameters:
        predicate - a predicate to filter credentials
      • invalidateAll

        public void invalidateAll()
        Discards all cached principals.
      • size

        public long size()
        Returns the number of cached principals.
        Returns:
        the number of cached principals
      • stats

        public com.github.benmanes.caffeine.cache.stats.CacheStats stats()
        Returns a set of statistics about the cache contents and usage.
        Returns:
        a set of statistics about the cache contents and usage