0
votes

I am currently using Hazelcast Community Edition as a caching mechanism used for a web application so it needs to be fast.

Currently, we store a lot of data in there and this is growing even more. As it's an in-memory DB, RAM is expensive. So wanted to know what the best practice was. I was planning to store only a small amount of data in the cache and store the rest in MongoDB. I want Hazelcast to persist and get the data from MongoDB only if it can't find it.

I have created the mapstore, but I am not sure how to tell it to "look" in MongoDB for data it can't find in the cache. Is it simply the case of getMap("something") if this result is empty then load("") from MapStore?

Thanks

1

1 Answers

0
votes

In EAGER mode it will load all the entries on the map init (so on hz.getMap()) In LAZY mode it will load a partition when it is first touched.

Additionally, if you do map.get() and there's no value in the IMap it will try loading that value from the MapLoader using MapLoader.load(key) method.

Also, if you do map.put() and there is no value in the IMap it will do MapLoader.load(key), since the put methods is supposed to return the previous value. If you want to avoid it use map.set().

It would be also good if you had a look at the manual section related to MapStore/MapLoader. It should describe all the subtle differences.