Hazelcast with Write through Cache using Mapstore

262 views
Skip to first unread message

anku...@gmail.com

unread,
Oct 21, 2015, 10:23:20 AM10/21/15
to Hazelcast

Hi,

I am using Hazelcast as caching Solution for my application.

My application has few inserts and updates to the database and these needs to be synced to Cache also.

 

I want to use MapStore functionality so that when I do IMap.put(), Hazelcast takes care of persisting the Object in underlying Db and also update its cache.

 

In the overridden store implementation, I want to call my DAO in following way to persist the Data.

 

    public void store(Long key, Product value)

        {

            log.info("Storing Data for Employee {} in Database using DataStore ",     value);

        Long employeeId = employeeDao.create(value);

        value.setId(employeeId);

   

    }

 

There are few issues listed below:-

1) In put call, I want to use "key" as the "employeeId", but this is generated only after insertion happens for this record in the Db. So how do I put into the Cache when I don't have the Id.? I want Hazelcast to use the "id" generated as part of store method call (or any other way) as the key to my Object.

 

> Imap.put(key,new Employee(<name of Employee>,<age of employee>))

 

2) The MapStore implementation's store method returns a void so I cannot return the Id generated for this Object to the Client. How can I achieve this?

I tried using MapEntryListeners on the Map but the entry added callback does not return new Object. I also added PostProcessingMapStore interface to my MapStore but could not get the new Value back to client.

 

Please advice

Enes Akar

unread,
Oct 22, 2015, 3:58:59 AM10/22/15
to Hazelcast
Hi;

You can set the generated id into any attribute of entry using PostProcessingMapStore.
But I do not know a way to set this id as a key.
Not to use mapstore instead inserting manually to db then putting into map with returned id seems feasible to me.



--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/7cc3eb9c-8ae7-46d6-be80-6fa13343082b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages