Class CaffeineCachingProvider

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, javax.cache.spi.CachingProvider

    public final class CaffeineCachingProvider
    extends java.lang.Object
    implements javax.cache.spi.CachingProvider
    A provider that produces a JCache implementation backed by Caffeine. Typically this provider is instantiated using Caching.getCachingProvider(), which discovers this implementation through a ServiceLoader.

    This provider is expected to be used for application life cycle events, like initialization. It is not expected that all requests flow through the provider to obtain the cache manager and cache instances for request operations. Internally, this implementation is synchronized to avoid using excess memory due to its infrequent usage.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  CaffeineCachingProvider.JCacheClassLoader
      A ClassLoader that combines Thread.currentThread().getContextClassLoader() and getClass().getClassLoader().
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.ClassLoader,​java.util.Map<java.net.URI,​javax.cache.CacheManager>> cacheManagers  
      private static java.lang.ClassLoader DEFAULT_CLASS_LOADER  
      private boolean isOsgiComponent  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void activate()  
      void close()  
      void close​(java.lang.ClassLoader classLoader)  
      void close​(java.net.URI uri, java.lang.ClassLoader classLoader)  
      javax.cache.CacheManager getCacheManager()  
      javax.cache.CacheManager getCacheManager​(java.net.URI uri, java.lang.ClassLoader classLoader)  
      javax.cache.CacheManager getCacheManager​(java.net.URI uri, java.lang.ClassLoader classLoader, java.util.Properties properties)  
      java.lang.ClassLoader getDefaultClassLoader()  
      java.util.Properties getDefaultProperties()  
      java.net.URI getDefaultURI()  
      private java.lang.ClassLoader getManagerClassLoader​(java.lang.ClassLoader classLoader)  
      private java.net.URI getManagerUri​(java.net.URI uri)  
      boolean isOsgiComponent()  
      boolean isSupported​(javax.cache.configuration.OptionalFeature optionalFeature)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_CLASS_LOADER

        private static final java.lang.ClassLoader DEFAULT_CLASS_LOADER
      • cacheManagers

        private final java.util.Map<java.lang.ClassLoader,​java.util.Map<java.net.URI,​javax.cache.CacheManager>> cacheManagers
      • isOsgiComponent

        private boolean isOsgiComponent
    • Constructor Detail

      • CaffeineCachingProvider

        public CaffeineCachingProvider()
    • Method Detail

      • getDefaultClassLoader

        public java.lang.ClassLoader getDefaultClassLoader()
        Specified by:
        getDefaultClassLoader in interface javax.cache.spi.CachingProvider
      • getDefaultURI

        public java.net.URI getDefaultURI()
        Specified by:
        getDefaultURI in interface javax.cache.spi.CachingProvider
      • getDefaultProperties

        public java.util.Properties getDefaultProperties()
        Specified by:
        getDefaultProperties in interface javax.cache.spi.CachingProvider
      • getCacheManager

        public javax.cache.CacheManager getCacheManager()
        Specified by:
        getCacheManager in interface javax.cache.spi.CachingProvider
      • getCacheManager

        public javax.cache.CacheManager getCacheManager​(java.net.URI uri,
                                                        java.lang.ClassLoader classLoader)
        Specified by:
        getCacheManager in interface javax.cache.spi.CachingProvider
      • getCacheManager

        public javax.cache.CacheManager getCacheManager​(java.net.URI uri,
                                                        java.lang.ClassLoader classLoader,
                                                        java.util.Properties properties)
        Specified by:
        getCacheManager in interface javax.cache.spi.CachingProvider
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface javax.cache.spi.CachingProvider
        Specified by:
        close in interface java.io.Closeable
      • close

        public void close​(java.lang.ClassLoader classLoader)
        Specified by:
        close in interface javax.cache.spi.CachingProvider
      • close

        public void close​(java.net.URI uri,
                          java.lang.ClassLoader classLoader)
        Specified by:
        close in interface javax.cache.spi.CachingProvider
      • isSupported

        public boolean isSupported​(javax.cache.configuration.OptionalFeature optionalFeature)
        Specified by:
        isSupported in interface javax.cache.spi.CachingProvider
      • getManagerUri

        private java.net.URI getManagerUri​(java.net.URI uri)
      • getManagerClassLoader

        private java.lang.ClassLoader getManagerClassLoader​(java.lang.ClassLoader classLoader)
      • activate

        private void activate()
      • isOsgiComponent

        public boolean isOsgiComponent()