Spring Boot Application and Hazelcast NearCache

516 views Asked by At

I am trying to use Hazelcast caching with Spring Boot, having read some documentation I decided to settle for Near Cache configurations, I would like to cache some method calls and use it for Hibernate L2 caching.. the trouble is I haven't exactly seen an example of using Near Cache specifically creating near cache clients and starting the server. Can I have some code examples for in configuring that setup (nearcache configurations) and how to start the server side.

1

There are 1 answers

0
ozcan On

Configure Hibernate to use Hazelcast client:

<!-- hibernate.cfg.xml --> 

<property name="hibernate.cache.hazelcast.use_native_client">true</property>
<property name="hibernate.cache.hazelcast.configuration_file_path">hazelcast-client.xml</property>

and in client config, configure near-cache:

<!-- hazelcast-client.xml -->

<near-cache name="default">
    <time-to-live-seconds>90</time-to-live-seconds>
    <max-idle-seconds>100</max-idle-seconds>
    <in-memory-format>OBJECT</in-memory-format>
</near-cache>

Alternatively, you can set different configurations for each cache region via:

<near-cache name="<entity-cache-region-name>">

These will enable client's near-cahce for Hibernate L2C. You do not need to add any additional config on server side at this point. However, if you also want to configure near-cache for members, you can configure them independently of Hibernate & client side.

Configuration details for both client and member are here in the documentation.