Hazelcast
Hazelcast provides a very nice set of features for distributed caching (which is what we use it for with L2 caching) plus "Data grid" features.
My expectation is that most people will prefer client/server mode with use of near caches.
Client/server mode
We can use Hazelcast in client/server
mode which means that our application uses a
Hazelcast client
to talk to a Hazelcast cluster (of servers).
In this mode the bean cache data is partitioned across all the Hazelcast servers in the cluster
and not in our application. We can choose to use a near cache
for some or all of our bean
types and in doing so improve performance (by having local data) but increase memory footprint in our
application (as it now holds some cache data).
Configuration
For client/server mode the configuration file should be a hazelcast-client.xml
Server mode
In server mode our application starts a Hazelcast server instance
which is a full fledged member
of the Hazelcast cluster. This means that it will hold data etc.
Configuration
For server mode the configuration file should be a hazelcast.xml
.
Dependency
Add a dependency to ebean-hazelcast
. When Ebean starts ebean-hazelcast is
automatically registered as the L2 cache implementation.
Disable L2 cache
During development and testing it is often useful to disable the use of the l2 cache.
Properties
## disable use of L2 cache (for dev / testing etc)
ebean.disableL2Cache=true
Configuration
XML configuration
Hazelcast will operate without any configuration but typically you will want to add a hazelcast-client.xml
or hazelcast.xml
configuration for client/server or server mode respectively.
In hazelcast-client.xml you can specify the use of near cache
for example which is a common need.
Programmatic configuration
You can programmatically configure Hazelcast by creating an instance of Hazelcast ClientConfig
or
Config
and setting it via:
ClientConfig configuration = ...;
serverConfig.setServiceObject("hazelcastConfiguration", configuration);
If this configuration instance is passed in Ebean will use it to configure a Hazelcast client or server instance. Otherwise it will use default configuration and Hazelcast will automatically search for and use the xml configuration files.
Getting started
- Annotate beans with @Cache
- Add maven dependency ebean-hazelcast
- Optionally add hazelcast-client.xml or hazelcast.xml
- For client/server mode you need a running Hazelcast server