Caching class provides a convenient means for an application to
acquire an appropriate CachingProvider implementation.
While defined as part of the specification, its use is not required.
Applications and/or containers may instead choose to directly instantiate a
CachingProvider implementation based on implementation specific
instructions.
When using the Caching class, CachingProvider implementations
are automatically discovered when they follow the conventions outlined by the
Java Development Kit ServiceLoader class.
Although automatically discovered, applications that choose to use this class
should not make assumptions regarding the order in which implementations are
returned by the getCachingProviders() or
getCachingProviders(ClassLoader) methods.
For a CachingProvider to be automatically discoverable by the
Caching class, the fully qualified class name of the
CachingProvider implementation must be declared in the following
file:
META-INF/services/javax.cache.spi.CachingProviderThis file must be resolvable via the class path.
For example, in the reference implementation the contents of this file are:
org.jsr107.ri.RICachingProvider
Alternatively when the fully qualified class name of a
CachingProvider implementation is specified using the system property
javax.cache.spi.cachingprovider, that implementation will be used
as the default CachingProvider.
All CachingProviders that are automatically detected or explicitly
declared and loaded by the Caching class are maintained in an
internal registry. Consequently when a previously loaded
CachingProvider is requested, it will be simply returned from the
internal registry, without reloading and/or instantiating the said
implementation again.
As required by some applications and containers, multiple co-existing
CachingProviders implementations, from the same or different
implementors are permitted at runtime.
To iterate through those that are currently registered a developer may use the following methods:
To request a specificCachingProvider implementation, a developer
should use either the getCachingProvider(String) or
getCachingProvider(String, ClassLoader) method.
Where multiple CachingProviders are present, the
CachingProvider returned by getters getCachingProvider() and
getCachingProvider(ClassLoader) is undefined and as a result a
CacheException will be thrown when attempted.
ServiceLoader, CachingProvider
| Modifier and Type | Class and Description |
|---|---|
| private static class | Caching.CachingProviderRegistry
Maintains a registry of loaded |
| Modifier and Type | Field and Description |
|---|---|
| private static final Caching. | CACHING_PROVIDERS
The |
| public static final String | JAVAX_CACHE_CACHING_PROVIDER
The |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static < the type of key K, the type of value V> Cache | Returns: the Cache or null if it does exist or can't be pre-configuredthe name of the managed cacheName, Class<K> Cache to acquirethe expected keyType, Class<V> Class of the keythe expected valueType)Class of the valueA convenience that method that looks up a managed |
| public static CachingProvider | Returns: theCachingProviderObtains the default |
| public static CachingProvider | Returns: theCachingProviderthe classLoader)ClassLoader to use for loading the
CachingProviderObtains the single |
| public static CachingProvider | Returns: theCachingProviderthe fully qualified class name of the
fullyQualifiedClassName)CachingProviderObtain the |
| public static CachingProvider | Returns: theCachingProviderthe fully qualified class name of the
fullyQualifiedClassName, ClassLoader CachingProviderthe classLoader)ClassLoader to load the
CachingProviderObtain the |
| public static Iterable | getCachingProviders()
Obtains the |
| public static Iterable | getCachingProviders(ClassLoader
the classLoader)ClassLoader of the returned
CachingProvidersObtains the |
| public static ClassLoader | Returns: the defaultClassLoaderObtains the |
| public static void | setDefaultClassLoader(ClassLoader classLoader)
Set the |
| CACHING_PROVIDERS | back to summary |
|---|---|
| private static final Caching. The | |
| JAVAX_CACHE_CACHING_PROVIDER | back to summary |
|---|---|
| public static final String JAVAX_CACHE_CACHING_PROVIDER The | |
| Caching | back to summary |
|---|---|
| private Caching() No public constructor as all methods are static. | |
| getCache | back to summary |
|---|---|
| public static <K, V> Cache A convenience that method that looks up a managed
This method must be used for
Implementations must ensure that the key and value types are the same as
those configured for the
Implementations may further perform type checking on mutative cache operations
and throw a
Implementations that support declarative mechanisms for pre-configuring
| |
| getCachingProvider | back to summary |
|---|---|
| public static CachingProvider getCachingProvider() Obtains the default
| |
| getCachingProvider | back to summary |
|---|---|
| public static CachingProvider getCachingProvider(ClassLoader classLoader) Obtains the single
| |
| getCachingProvider | back to summary |
|---|---|
| public static CachingProvider getCachingProvider(String fullyQualifiedClassName) Obtain the
| |
| getCachingProvider | back to summary |
|---|---|
| public static CachingProvider getCachingProvider(String fullyQualifiedClassName, ClassLoader classLoader) Obtain the
| |
| getCachingProviders | back to summary |
|---|---|
| public static Iterable Obtains the
If a
| |
| getCachingProviders | back to summary |
|---|---|
| public static Iterable Obtains the
If a
| |
| getDefaultClassLoader | back to summary |
|---|---|
| public static ClassLoader getDefaultClassLoader() Obtains the
By default this is the
| |
| setDefaultClassLoader | back to summary |
|---|---|
| public static void setDefaultClassLoader(ClassLoader classLoader) Set the
| |
CachingProviders scoped by
ClassLoader.
| Modifier and Type | Field and Description |
|---|---|
| private WeakHashMap | cachingProviders
The |
| private volatile ClassLoader | classLoader
The default |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public CachingProvider | Returns: theCachingProviderObtains the only |
| public CachingProvider | Returns: theCachingProviderthe classLoader)ClassLoader to use for loading the
CachingProviderObtains the only |
| public CachingProvider | Returns: theCachingProviderthe fully qualified class name of the
fullyQualifiedClassName)CachingProviderObtain the |
| public synchronized CachingProvider | Returns: theCachingProviderthe fully qualified class name of the
fullyQualifiedClassName, ClassLoader CachingProviderthe classLoader)ClassLoader to load the
CachingProviderObtain the |
| public Iterable | getCachingProviders()
Obtain the |
| public synchronized Iterable | getCachingProviders(ClassLoader
the classLoader)ClassLoader of the returned
CachingProvidersObtain the |
| public ClassLoader | Returns: the defaultClassLoaderObtains the |
| protected CachingProvider | Returns: a newCachingProvider instancethe name of the fullyQualifiedClassName, ClassLoader CachingProvider
classthe classLoader)ClassLoader to useLoad and instantiate the |
| public void | setDefaultClassLoader(ClassLoader classLoader)
Set the |
| cachingProviders | back to summary |
|---|---|
| private WeakHashMap<ClassLoader, LinkedHashMap<String, CachingProvider>> cachingProviders The | |
| classLoader | back to summary |
|---|---|
| private volatile ClassLoader classLoader The default | |
| CachingProviderRegistry | back to summary |
|---|---|
| public CachingProviderRegistry() Constructs a CachingProviderManager. | |
| getCachingProvider | back to summary |
|---|---|
| public CachingProvider getCachingProvider() Obtains the only
Should zero or more than one
| |
| getCachingProvider | back to summary |
|---|---|
| public CachingProvider getCachingProvider(ClassLoader classLoader) Obtains the only
Should zero or more than one
| |
| getCachingProvider | back to summary |
|---|---|
| public CachingProvider getCachingProvider(String fullyQualifiedClassName) Obtain the
| |
| getCachingProvider | back to summary |
|---|---|
| public synchronized CachingProvider getCachingProvider(String fullyQualifiedClassName, ClassLoader classLoader) Obtain the
| |
| getCachingProviders | back to summary |
|---|---|
| public Iterable Obtain the
If a
| |
| getCachingProviders | back to summary |
|---|---|
| public synchronized Iterable Obtain the
If a
| |
| getDefaultClassLoader | back to summary |
|---|---|
| public ClassLoader getDefaultClassLoader() Obtains the
By default this is the
| |
| loadCachingProvider | back to summary |
|---|---|
| protected CachingProvider loadCachingProvider(String fullyQualifiedClassName, ClassLoader classLoader) throws CacheException Load and instantiate the
| |
| setDefaultClassLoader | back to summary |
|---|---|
| public void setDefaultClassLoader(ClassLoader classLoader) Set the
| |