JBoss.org Community Documentation

9.1.4. Programmatic Configuration

Configuring eviction using the Configuration object entails the use of the org.jboss.cache.config.EvictionConfig bean, which is passed into Configuration.setEvictionConfig() . See the chapter on Configuration for more on building a Configuration programatically.

The use of simple POJO beans to represent all elements in a cache's configuration also makes it fairly easy to programatically add eviction regions after the cache is started . For example, assume we had an existing cache configured via XML with the EvictionConfig element shown above. Now at runtime we wished to add a new eviction region named "/org/jboss/fifo", using LRUPolicy but a different number of maxNodes :



   Fqn fqn = Fqn.fromString("/org/jboss/fifo");

   // Create a configuration for an LRUPolicy
   LRUConfiguration lruc = new LRUConfiguration();
   lruc.setMaxNodes(10000);

   // Create the region and set the config
   Region region = cache.getRegion(fqn, true);
   region.setEvictionPolicy(lruc);