Core Module
Contains the ServiceLocator, as well as core SPI interfaces.
CacheManager
and its Cache
instances
The CacheManager
not only acts as a repository of Cache
instances, but it also lifecycles them. The CacheManager
is also responsible for lifecycling Service
instances. These Service
instances are provided by the CacheManager
for its Cache
instances to use. The Cache
and Service
instances can look up any Service
by it’s type by querying the ServiceLocator
.
The ServiceLocator
Every CacheManager
has its own ServiceLocator
instance. The ServiceLocator
acts as a repository of concrete Service
which can then be looked up by type. The Service
instances it knows about are the ones provided to it at CacheManager
construction time. Service
instances can be injected directly, but will more generally be declared for use by providing a matching ServiceConfiguration
to the CacheManagerBuilder
. Not all Service
are necessarily required to be user facing (through one of their ServiceConfiguration
for instance). If a requested Service
can’t be found, it’ll be looked up using Java’s ServiceLoader
facility from the classpath.
The ServiceLoader
fallback for Service
lookups can be used by the end-user, but is expected to be used mainly by anyone building an Ehcache Distribution (i.e. a so-called überjar created by some mean from all the different modules that composes it). The idea is to only couple different Service
to the minimal and the strictly required level.
Configuration types
Minimal configurations
In order to create a CacheManager
, you need to configure CacheConfiguration
for each and every Cache
instance you want to use. You also may need to configure some additional Service
instances one or some of your Cache
need. Whether configured directly at the CacheManager
level, or at the Cache
level, a given ServiceConfiguration
will be used by a single Service
instance. But the Service
itself may configure itself further for a given Cache
.
The interface Store.Provider extends Service
as an example
There will be only one Store.Provider
instance registered for that type that the CacheManager
will lookup using the ServiceLocator
when creating a Cache
instance. The Store.Provider
acts as a factory for Store
instances. That factory may delegate to specialized implementations of Store.Provider
it knows about (e.g. OnHeapStoreProvider
, DiskStoreProvider
, …) by looking at the Store.Configuration
it’s been asked to configure the Store
instance for.
What that Store.Provider
instance it’ll be can either be specified by injecting one directly into the ServiceLocator
backing up the CacheManager
to create the Cache
instances. Or have it fallback to the classpath of the application to resolve one. Where the ServiceLoader
facility is only resorted to, if none injected instance could be found.