spring-bootinfinispanjgroupsehcache-2

infinispan embedded Cache with Invalidation mode and putForExternalRead


We are running a cluster of 30+ servers with massive caching to improve our performance. We use Spring Boot. We have

We used EhCache 2.x with JGroups Replication before. It was configured with

replicatePuts=false

This sets "whether new elements placed in a cache are replicated to others.". See https://www.ehcache.org/documentation/2.8/replication/jgroups-replicated-caching.html#example-configuration-using-udp-multicast

Now we switched to Infinispan 13.x.

Hibernate is easy as Infinispan configures everything just fine. It uses putForExternalRead under the hood if the key is not already in the cache. For our Local Application Caches, which are not replicated, everything works fine, too.

We had problems with our Application Caches in Invalidation mode. These are configured like this:

embeddedCacheManager.defineConfiguration(NAME, 
   new ConfigurationBuilder()
   .memory()
     .maxCount(10000)
     .whenFull(EvictionStrategy.REMOVE)
   .statistics()
      .enabled(true)
   .expiration()
      .maxIdle(-1)
      .lifespan(-1)
   .clustering()
     .cacheMode(CacheMode.INVALIDATION_ASYNC)
   .build());

When we put a new Object into the cache with

 cache.put(key, value)

This put results in an invalidation message to the cluster and all other nodes remove this key from the cache.

Of course, we found out, that we can use the following method instead:

 cache.putForExternalRead(key, value)

This has many drawbacks:

It would be nice to configure some caches to use always putForExternalRead under the hood if a new element is put into the cache. Something like

   .clustering()
     .cacheMode(CacheMode.INVALIDATION_ASYNC)
     .replicatePuts(false)

Is it possible to achieve this? Is it possible to use an interceptor or listener to avoid sending the invalidation message on new object?

for me it makes so much sense the way ehcache is doing it. I am wondering if I misunderstood something or if infinspan just can't handle this situation.


Solution

  • I dont think its possible to configure Infinispan to use putForExternalRead under the hood if a new element is put into the cache in invalidation mode. because invalidation mode is designed to send invalidation messages to other nodes in the cluster when a new object is added to the cache, and using putForExternalRead would not send those messages. but you may be able to do the same thing by using a cache listener or interceptor to intercept cache operations and only send invalidation messages when necessary. Or maybe just use replication mode, which would replicate new objects to all nodes in the cluster instead of sending invalidation messages.