I'm using EhCache 2.10.2. Synchronous replication (replicateAsynchronously=false) between two servers (S1 and S2).
I have next situation:
- First HTTP request going to S1
- S1 can't find object in cache and loads it from DB with state "A" and puts to cache
- S1 changes object's state to "B", saves to DB and puts to cache
- S1 sends success response
- Next request going to S2
- S2 finds obect in cache with state "A"
- S2 sends error response, because object must have state "B" on second request.
When server puts object to cache, thread blocked on put operation only to send serialized object to another server, and don't wait while another server deserialize and put element to cache. So at point 6 can be state "A" or "B", if we get lucky.
Is it possible to configure EhCache to block operations until changes replicated on all nodes?
May be I need to replace EhCache with other cache implementation, or change everything?