On Wildfly 10.0.0 I'm running into an issue where I'm expecting Wildfly to use an Infinispan invalidation cache but it ends up using a local cache so invalidation doesn't happen correctly of the second level cache (consistency issues between nodes). I verified this was a local cache by looking at the JMX MBeans (where the entity caches have local-cache in the configuration details). This is what my Wildfly XML looks like for the Hibernate cache manager:
<cache-container name="hibernate" default-cache="local-query" module="org.hibernate.infinispan"> <transport lock-timeout="60000"/> <local-cache name="local-query"> <eviction strategy="LRU" max-entries="10000"/> <expiration max-idle="100000"/> </local-cache> <invalidation-cache name="entity" statistics-enabled="true" mode="SYNC"> <transaction mode="NON_XA"/> <eviction strategy="LRU" max-entries="10000"/> <!-- MGP - increase cache expiration to 15 minutes as the default of 100 seconds is too low --> <expiration max-idle="900000"/> </invalidation-cache> <replicated-cache name="timestamps" mode="ASYNC"/> </cache-container>
The only change I made from the standard configuration was to increase the max-idle expiration and tried to enable statistics on the entity cache. This may be because I'm confusing how this actually works, I thought the defined "entity" cache was basically a template for any Hibernate second level entity cache and it would use this and create a cache per entity following the invalidation configuration. When I debugged the Wildfly/Hibernate/Infinispan execution though it looks like the EmbeddedCacheManager.getCache is getting called with a name per entity e.g. com.mycompany.entityName - the configuration for this then just seems to default to local cache. Do I have to configure an invalidation cache explicitly per entity or is there someway to create a "template" for the default entity cache?
Other relevant information that may be affecting this is Wildfly is not creating the persistent unit, I'm essentially using the configuration detailed here - https://docs.jboss.org/author/display/WFLY8/Spring+applications+development+and+migration+guide - specifically the "Using Spring-managed persistence units" section - I'm not sure if this is may be affecting things since Spring is creating the EntityManagerFactory rather than Wildfly. I've tried explicitly configuring the region factory in my persistence.xml to try using the SharedInfinispanRegionFactory (provided by Wildfly) and the JndiInfinispanRegionFactory (provided by Hibernate) but I got the same results. Also for the "timestamps" cache I don't actually see this cache via JMX but instead see a cache with the name "org.hibernate.cache.spi.UpdateTimestampsCache" and it is local instead of the expected replicated/async (again could be a misunderstanding of how this is supposed to work).
Session clustering does work correctly, I see the replicated "web" cache and this works as expected just entity caching for Hibernate isn't defaulting to the expected caches (or I'm missing the configuration here!). Thanks!
Guides I've looked at for reference:
Older guide about Infinispan as the second level cache provider for JPA - https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+JPA-Hibernate+Second+Level+Cache+Provider - talks about how you can configure each individual cache differently but I'm not sure what part Wildfly plays here in managing the configuration.