Chapter 4. Eviction Policies

4.1.

Does JBoss Cache support eviction policies?

Yes. JBoss Cache currently implements a LRU eviction policy for both TreeCache ( org.jboss.cache.eviction.LRUPolicy ) and PojoCache ( org.jboss.cache.aop.eviction.AopLRUPolicy ). Users can also plug in their own eviction policy algorithms. See user manual for details. Currently there is user-contributed policy called FIFOPolicy that evicts the node based on FIFO principle only.

4.2.

Why can't I use org.jboss.cache.eviction.LRUPolicy for PojoCache as well?

For PojoCache, you will need to use org.jboss.cache.aop.eviction.AopLRUPolicy ) because AOP has its eviction algorithm, although is LRU but has totally different notion of an "object", for example.

4.3.

Does JBoss Cache's implemented LRU eviction policy operates in replication mode?

Yes and no. :-)

The LRU policy only operates in local mode. That is, nodes are only evicted locally. This may cause the cache contents not to be synchronized temporarily. But when a user tries to obtain the cached contents of an evicted node and finds out that is null (e.g., get returns null), it should get it from the other data source and re-populate the data in the cache. During this moment, the node content will be propagated and the cache content will be in sync.

However, you still can run eviction policies with cache mode set to either REPL_SYNC or REPL_ASYNC . Depending on your use case, you can set multiple cache instances to have their own eviction policy (which are applied locally) or just have selected instances with eviction policies activated.

Also note that, with cache loader option, a locally evicted node can also be persisted to the backend store and a user can retrieve it from the store later on.

4.4.

Does JBoss Cache support Region ?

Yes. JBoss Cache has the notion of region where a user can configure the eviction policy parameters (e.g., maxNodes or timeToIdleSeconds )

A region in JBoss Cache denotes a portion of tree hierarchy, e.g., a fully qualified name ( FQN ). For example, a user can define /org/jboss and /org/foocom as two separate regions. But note that you can configure the region programmatically now, i.e., everything has to be configured through the xml file.

4.5.

What are the EvictionPolicyConfig tag parameters for org.jboss.cache.eviction.LRUPolicy ?

They are:

Table 4.1. Parameters

wakeUpIntervalInSecondsInterval where the clean up thread wakes to process the sitting queue and sweep away the old data.
regionA area where each eviction policy parameters are specified. Note that it needs a minimum of /_default region.
maxNodesMax number of nodes allowed in the eviction queue. 0 means no limit.
timeToLiveInSecondsAge (in seconds) for the node to be evicted in the queue. 0 denotes no limit.
4.6.

I have turned on the eviction policy, why do I still get "out of memory" (OOM) exception?

OOM can happen when the speed of cache access exceeds the speed of eviction policy handling timer. Eviction policy handler will wake up every wakeUpIntervalInSeconds seconds to process the eviction event queue. And the queue size is fixed at 20000 now. So when the queue size is full, it will create a backlog and cause OOM to happen unless the eviction timer catches up. To address this problem, in addition to increase the VM heap size, you can also reduce the wakeUpIntervaleInSeconds so the timer thread processes the queue more frequently.

We will also externalize the queue size so it will be configurable in the next release.