[Java programming language only]

Configuring evictors with XML files

In addition to programmatically setting a time-to-live (TTL) evictor with the BackingMap interface, you can use an XML file to configure an evictor on each BackingMap instance.

Before you begin

Before you begin, decide on the type of evictor you are going to use:
  • The default time-based TTL evictor: The default evictor uses a time-to-live (TTL) eviction policy for each BackingMap instance.
  • A pluggable evictor mechanism: Pluggable evictors typically use an eviction policy that is based on the number of entries instead of on time.
Set the evictor settings before you start your container servers.

Procedure

  • To set the default TTL evictor, add the ttlEvictorType attribute to the ObjectGrid descriptor XML file.

    The following example shows that the map1 BackingMap instance uses a NONE TTL evictor type. The map2 BackingMap instance uses either a LAST_ACCESS_TIME or LAST_UPDATE_TIME TTL evictor type. Specify only one or the other of these settings. The map2 BackingMap instance has a time-to-live value of 1800 seconds, or 30 minutes. The map3 BackingMap instance is defined to use a CREATION_TIME TTL evictor type and has a time-to-live value of 1200 seconds, or 20 minutes.

    Figure 1. Enable TimeToLive evictor with XML
    <?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
     xmlns="http://ibm.com/ws/objectgrid/config">
    <objectGrids>
        <objectGrid name="grid1">
            <backingMap name="map1" ttlEvictorType="NONE" />
            <backingMap name="map2" ttlEvictorType="LAST_ACCESS_TIME|LAST_UPDATE_TIME" 
    					timeToLive="1800" />
            <backingMap name="map3" ttlEvictorType="CREATION_TIME" 
    					timeToLive="1200" />
        </objectgrid>
    </objectGrids>
  • To set a pluggable evictor, use the following example.
    Figure 2. Plugging in an evictor using XML
    <?xml version="1.0" encoding="UTF-8"?>
    <objectGridConfig xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://ibm.com/ws/objectgrid/config ../objectGrid.xsd"
     xmlns="http://ibm.com/ws/objectgrid/config">
    <objectGrids>
        <objectGrid name="grid">
            <backingMap name="map1" ttlEvictorType="NONE" pluginCollectionRef="LRU" />
            <backingMap name="map2" ttlEvictorType="NONE" pluginCollectionRef="LFU" />
        </objectGrid>
    </objectGrids>
    <backingMapPluginCollections>
        <backingMapPlugincollection id="LRU">
            <bean id="Evictor" className="com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor">
                <property name="maxSize" type="int" value="1000" description="set max size 
    							for each LRU queue" />
                <property name="sleepTime" type="int" value="15" description="evictor 
    							thread sleep time" />
                <property name="numberOfLRUQueues" type="int" value="53" description="set number 
    							of LRU queues" />
            </bean>
        </backingMapPluginCollection>
        <backingMapPluginCollection id="LFU">
            <bean id="Evictor"	className="com.ibm.websphere.objectgrid.plugins.builtins.LFUEvictor">
                <property name="maxSize" type="int" value="2000" description="set max size for each LFU heap" />
                <property name="sleepTime" type="int" value="15" description="evictor thread sleep time" />
                <property name="numberOfHeaps" type="int" value="211" description="set number of LFU heaps" />
            </bean>
        </backingMapPluginCollection>
    </backingMapPluginCollections>
    </objectGridConfig>
[Version 8.6 and later]

What to do next

If you want to configure the TTL metadata to be updated when the near cache is used, see Configuring the near cache to update the LAST_ACCESS_TIMEvalue for the TTL evictor in the data grid.