I attempted to solve this problem by implementing a custom cache loader (a cache loader can be used to preload cache entries before the cluster is formed). However, the missing part is to have Spring create the cache loader instance. This is necessary in my case, as the cache loader needs to access DAO objects that are maintained by Spring. When configuring caches either via XML or programmatically, it is not possible to pass the cache loader instance. Instead, the cache loader is instantiated by Infinispan using the cache loader class name. Is there another way to solve this?
I finally managed to solve this without using Infinispan-specific loaders, which in my opinion are not intended for this task. In case someone is interested, this is the approach I taken:
1. Integrate Infinispan with Spring using infinispan-spring module
2. Implement a Spring ApplicationListener, which preloads the cache from the database using injected Infinispan's EmbeddedCacheLoader and a custom DAO managed by Spring. (The preloading code should be executed from the onApplicationEvent() method to ensure that Spring container is fully initialized).
The trick is then to use a local mode when storing entries in the cache, i.e:
Cache<String, String> cache = cacheManager.getCache("myCache");
AdvancedCache<String, String> advancedCache = cache.getAdvancedCache();
This way any RPC messages will be suppressed (stored entries will not get replicated to other nodes in the cluster).