Since Ehcache is a library and supports user types both in configuration and in mapping keys or values, it must offer flexibility around class loading.
ClassLoader from Ehcache will first try to use the thread context class loader, through
In case this fails to load the requested resource, it will then use the
ClassLoader that loaded the Ehcache internal classes.
The way to configure a
ClassLoader and the scope of its use differ between Java and XML based configurations.
However, regardless of the configuration method, each
Cache is always linked individually to a specific
During the configuration of the
Cache, there are multiple extension points where a user type can be involved.
CacheLoaderWriter and other similar companion objects.
You can usually give an instance of these types to the configuration or an instance of the class to use.
This effectively negates the need to think in terms of a class loader here.
However you can still pass a specific
ClassLoader to the
You can also give a specific
ClassLoader per cache if you need to, taking precedence over the one configured at the
These will be used at runtime.
If no class loader is specified, the default class loader from Ehcache will be used.
When using XML to configure Ehcache, references to custom types are given through a fully qualified class name.
This means that transforming these
String names into the proper class representation may require a specific
In order to support this, the
XmlConfiguration constructors can take
public XmlConfiguration(URL url)
to use only default
public XmlConfiguration(URL url, final ClassLoader classLoader)
to use a specific
public XmlConfiguration(URL url, final ClassLoader classLoader, final Map<String, ClassLoader> cacheClassLoaders)
to use a specific
CacheManagerlevel and a map of
<String, ClassLoader>which will be used to link a specific
Cacheby its alias
In the same way as for the Java configuration, the
Cache level configuration takes precedence over the
CacheManager level one.
If no class loaders are specified, the default class loader from Ehcache will be used.