Search code examples
cachingjbosswildflyinfinispan

Infinispan - Can I create DefaultCacheManager for each web application in the server


I do not understand the following statement of DefaultCacheManager's Java doc. It says

CacheManagers are heavyweight objects, and we foresee no more than one CacheManager being used per JVM

  • Am I allowed to create DefaultCacheManager programmatically for each web application in the server? For example, I have two web applications, A and B. They are running in the JBoss AS (standalone only). Each web application (A and B) creates own DefaultCacheManager object.

Solution

  • Yes, you can create more cache managers. The term heavyweight here means that cache manager contains thread pools, JGroups channels (that means consumed ports) etc. so you should not create too many of these.

    The situation might be a bit different in an application server with deep integration - some of the resources can be shared there. Check out the Infinispan subsystem - cache manager then maps to a cache-container. It's perfectly fine to have multiple cache containers in the configuration.

    In application server, the applications should not create the cache managers; these should be only injected (e.g. through CDI) to your webapp.