Pregunta

Estoy planeando implementar una solución de caché en una aplicación web existente. Nada complicado: básicamente un mapa concurrentes que los apoyos que desborda en el disco y el desalojo automático. La agrupación de la caché podría ser requisito en el futuro, pero no ahora.

Me gusta copyOnRead de ehcache y cuenta con copy-on-write, porque significa que no tengo a cosas clon manualmente antes de modificar algo que sacar de la memoria caché. Ahora he empezado a ver Infinispan , pero no he encontrado nada equivalente allí. ¿Existe?

.

es decir, las siguientes pruebas de unidad deben pasar:

@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));
}
¿Fue útil?

Solución

According to a JBoss developer, Infinispan does not yet support such feature. You should log a request for enhancement in the Infinispan issue tracker, so that others may vote on it (I will).

That being said, if you need this feature now, a workaround would be to extend AbstractDelegatingCache, and override the get and put methods to add this functionality. You could use your own copy strategy or look at how EHCache did it for inspiration.

Also, you may consider the Infinispan forum if you have further questions, since you will have more views from the Infinispan community.

Otros consejos

Infinispan does support copyOnRead/copyOnWrite, albeit the actual format isn't pluggable. The configuration element is lazyDeserialization in Infinispan 4.x and storeAsBinary in Infinispan 5.x. Objects are serialized using the pluggable Marshaller framework, which is used for all forms of marshalling including for RPC calls over a network and storage to disk.

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

This also means the testcases in the question could pass if the owner of key 0 is not the current node, but it would still fail if it's a single node environment.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top