Juan Vega
Juan Vega

Reputation: 1120

How to configure Hazelcast using JCache programmatically and using writw behind?

I'm trying to add to the current implementation of the app I'm working on a JCache compliant technology. At the moment, I've been able to use Apache Ignite and have it working with a couple of caches using an implementation of a cache store to read from and write to a database. The writes are done using write behind in batches. Some of the configuration is not part of JCache but I've been able to add it through the extended class of MutableConfiguration provided by Ignite. Also, I've done this using Spring without any CacheProvider or CacheManager so in my config class I expose the caches directly as beans. I get them from the Ignite class that accepts my configuration class and allows me to get the caches by name. Now I'm trying to port this configuration to Hazelcast but I'm having problems doing it.

For starts, I haven't been able to find a way to configure the cache programmatically without an xml file. All examples I've found are using the the CacheManager that takes a Properties object with the path to this file. Would it work if I pass a path to a class instead of an xml?

I've seen that the Config.class used to configure a HazelcastInstance accepts a CacheSimpleConfig but then, HazelcastInstance doesn't have a getCache method or similar. If I configure the cache this way, how can I then get the cache from the HazelcastInstance?

Last thing, I've noticed there is no documentation related to configure write behind for a cache, only for maps. Is this not possible? Do caches only allow write through?

Thanks!

Upvotes: 0

Views: 1813

Answers (1)

emrahkocaman
emrahkocaman

Reputation: 493

  1. Since write-behind is not in the current JCache spec. it's also not in Hazelcast. From Ignite's documentation,

"Ignite provides org.apache.ignite.cache.store.CacheStore interface which extends both, CacheLoader and CacheWriter."

This means you've to use Ignite's proprietary API to get write-behind functionality. IMHO using JCache is useless since you'll have a vendor lock-in in that case. Aim of JCache spec is to end all proprietary caching APIs.

If you'd like to use properietary APIs, then I'd recommend you to use Hazelcast's IMap to get write-behind functionality.

  1. You can pass cache config programmatically while creating the cache;

Caching.getCachingProvider().getCacheManager().createCache("cache", cacheConfig);

Also below sample project can be useful;

https://github.com/hazelcast/hazelcast-code-samples/tree/master/hazelcast-integration/spring-jcache

It shows both XML and Java configuration.

Upvotes: 3

Related Questions