Infinispan is equivalent to ehcache copyOnRead and copyOnWrite

I plan to implement a caching solution in an existing web application. Nothing complicated: basically a parallel card that supports disk overflow and automatic eviction. Clustering the cache may be required in the future, but not now.

I like the ehcache functions copyOnRead and copyOnWrite because it means I don’t have to manually clone things before changing anything that I take out of the cache. Now I started watching Infinispan , but I did not find anything equivalent there. He exists?

Ie must pass the following unit tests:

@Test public void testCopyOnWrite() { Date date = new Date(0); cache.put(0, date); date.setTime(1000); date = cache.get(0); assertEquals(0, date.getTime()); } @Test public void testCopyOnRead() { Date date = new Date(0); cache.put(0, date); assertNotSame(cache.get(0), cache.get(0)); } 
+4
source share
3 answers

According to the developer JBoss, Infinispan does not yet support this feature. You must register the request for improvement in the Infinispan tracker so that others can vote on it (I will).

If you need this function now , the workaround is to extend the AbstractDelegatingCache extension, and override the get and put methods to add this functionality. You can use your own copy strategy or see how EHCache did this for inspiration.

In addition, you can consider the Infinispan forum if you have additional questions, as you will have more views from the Infinispan community.

+2
source

Infinispan supports copyOnRead / copyOnWrite, although the actual format is not connected. The lazyDeserialization configuration item in Infinispan 4.x and storeAsBinary in Infinispan 5.x. Objects are serialized using the Marshaller plug-in, which is used for all sorting forms, including RPC calls over the network and storage to disk.

+7
source

I believe that storeAsBinary takes effect only when the objects need to be serialized, which means that when the put operation is called, the owner is not the current node.

It also means that the test files in the question can pass if the owner of key 0 not the current node, but it will still fail if it has one node environment.

0
source

Source: https://habr.com/ru/post/1310866/


All Articles