In distribution/replication mode, Infinispan always stores a copy of the object you've passed in, to prevent concurrency issues. So if you insert an entry and then modify the value, these changes won't be reflected - you have to insert it again.
Note that local caches store just a reference to the object, for efficiency reasons.
Yes. I know it. I want to get the unmodified copy in the node where I change it before I put it again. How can I get it? I call cache.get(), but it returns me the modifed copy.
For example I begin a work. And I meet some failure.Then I rollback the transaction. The put will be reverted. But the object is modified. I want to revert it as well. So I need a way to get the unmodified copy.
Uh, I've tried a test to verify and I was partially wrong; it actually can store the original object if this node is a primary owner. So, the answer is: don't modify the original object, ideally you should make it immutable, because you can't really know if the object is about to be stored on local or remote node (so you can't know if the modification will have any effect). If you can't guarantee that, you should create a defensive copy yourselves. Or, as an alternative, you can configure store-as-binary which will always serialize the object when storing that (and keep the serialized form).
A deep copy myself, or store-as-binary? Which one do you recommend?
It seems that a fast deep copy implementation uses serialization. It seems that it's the same as story-as binary.
With store-as-binary, the object will be held as binary blob and whenever you'll read it locally, this blob will have to be deserialized. On the other hand, when the object is held as instance, it has to be serialized when it is read from remote node.
Just setting store-as-binary is probably simpler, it does not require any code changes. Besides that, the choice is only a matter of performance in your use case.