1
votes

I am developing a Clustered Web Application with different WARS deployed, so I need session sharing (and not only this). I've started using Ignite as a good platform for Clustered(Replicated) cache server. The issue I reached is this: My cache Key is String and Value is a HashMap

CacheConfiguration<Integer, Map<String,String>> cfg = new CacheConfiguration<>("my_cache");

I am using this cache as a WEBSESSION. The issue is where one servlet gets the Map, Put some session specific values, and put it back to Ignite. After the first servlet gets the cache, second one enters and because it finishes after the first one, the second put will kill first one changes.

So my exact question is, what's the pattern to have concurrent map access issue solved is a high efficient way (without whole object locking).

Regards

1

1 Answers

0
votes

It sounds a bit weird to me, because this scenario should be only possible when two there are two concurrent requests working with the same session. How is this possible?

But in any case, you can use TRANSACTIONAL cache for web session data. This will guarantee that these two requests will be processed within a lock and the data will be updated atomically.

<bean class="org.apache.ignite.configuration.CacheConfiguration">
    <property name="name" value="web-sessions-cache"/>
    <property name="atomicityMode" value="TRANSACTIONAL"/>
</bean>