public final class Caching extends Object
ServiceLoader
For a provider to be discovered, its jar must contain a resource called:
META-INF/services/javax.cache.spi.CachingProvidercontaining the class name implementing
CachingProvider
For example, in the reference implementation the contents are:
"javax.cache.implementation.RIServiceFactory"
If more than one CachingProvider is found, getCacheManagerFactory will throw an exception
Also keeps track of all CacheManagers created by the factory. Subsequent calls
to getCacheManager()
return the same CacheManager.ServiceLoader
,
CachingProvider
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CACHE_MANAGER_NAME
The name of the default cache manager.
|
Modifier and Type | Method and Description |
---|---|
static void |
close()
Reclaims all resources obtained from this factory.
|
static boolean |
close(ClassLoader classLoader)
Reclaims all resources for a ClassLoader from this factory.
|
static boolean |
close(ClassLoader classLoader,
String name)
Reclaims all resources for a ClassLoader from this factory.
|
static CacheManager |
getCacheManager()
Get the default cache manager with the default classloader.
|
static CacheManager |
getCacheManager(ClassLoader classLoader)
Get the default cache manager.
|
static CacheManager |
getCacheManager(ClassLoader classLoader,
String name)
Get a named cache manager.
|
static CacheManager |
getCacheManager(String name)
Get a named cache manager using the default cache loader as specified by
the implementation.
|
static CacheManagerFactory |
getCacheManagerFactory()
Get the singleton CacheManagerFactory
|
static boolean |
isAnnotationsSupported()
Indicates whether annotations are supported
|
static boolean |
isSupported(OptionalFeature optionalFeature)
Indicates whether a optional feature is supported by this implementation
|
public static final String DEFAULT_CACHE_MANAGER_NAME
getCacheManager()
is invoked.
The default CacheManager is always created.public static CacheManagerFactory getCacheManagerFactory()
IllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static CacheManager getCacheManager()
DEFAULT_CACHE_MANAGER_NAME
IllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static CacheManager getCacheManager(ClassLoader classLoader)
DEFAULT_CACHE_MANAGER_NAME
classLoader
- the ClassLoader that should be used in converting values into Java Objects. May be null.IllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static CacheManager getCacheManager(String name)
name
- the name of the cache managerNullPointerException
- if name is nullIllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static CacheManager getCacheManager(ClassLoader classLoader, String name)
CachingProvider
so that an implementation it to concrete implementations may use it to point to a specific configuration
used to configure the CacheManager. This allows CacheManagers to have different configurations. For example,
one CacheManager might be configured for standalone operation and another might be configured to participate
in a cluster.
Generally, It makes sense that a CacheManager is associated with a ClassLoader. I.e. all caches emanating
from the CacheManager, all code including key and value classes must be present in that ClassLoader.
Secondly, the Caching may be in a different ClassLoader than the
CacheManager (i.e. the Caching may be shared in an application server setting).
For this purpose a ClassLoader may be specified. If specified it will be used for all conversion between
values and Java Objects. While Java's in-built serialization may be used other schemes may also be used.
Either way the specified ClassLoader will be used.
The name parameter may be used to associate a configuration with this CacheManager instance.classLoader
- the ClassLoader that should be used in converting values into Java Objects.name
- the name of this cache managerNullPointerException
- if classLoader or name is nullIllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static void close() throws CachingShutdownException
CacheManager cacheManager = CacheFactory.getCacheManager(); assertSame(cacheManager, CacheFactory.getCacheManager()); CacheFactory.close(); assertNotSame(cacheManager, CacheFactory.getCacheManager());
CachingShutdownException
- if any of the individual shutdowns failedIllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static boolean close(ClassLoader classLoader) throws CachingShutdownException
classLoader
- the class loader for which managers will be shut downCachingShutdownException
- if any of the individual shutdowns failedIllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static boolean close(ClassLoader classLoader, String name) throws CachingShutdownException
classLoader
- the class loader for which managers will be shut downname
- the name of the cache managerCachingShutdownException
- if any of the individual shutdowns failedIllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static boolean isSupported(OptionalFeature optionalFeature)
optionalFeature
- the feature to check forIllegalStateException
- if no CachingProvider is found or if more than one CachingProvider is foundpublic static boolean isAnnotationsSupported()
Copyright © 2015 WSO2 Inc. All rights reserved.