To control the size of the near cache, configure a client-side override that enables an evictor on the client.
Use the following ObjectGrid XML file as an example to create a client-side configuration file. The client-side configuration file must specify either the default map name that corresponds to your data grid name or one of the template map names. For more information about the template map names, see Dynamic map configuration options. For example, the following sample configures a least recently used (LRU) evictor for all maps based on the *.NONE.NCI template map definition:
<?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="CompanyGrid">
<backingMap name=".*\.NONE\.NCI" nearCacheEnabled="true"
pluginCollectionRef="customerPlugins" />
</objectGrid>
</objectGrids>
<backingMapPluginCollections>
<backingMapPluginCollection id="customerPlugins">
<!-- Limit the near cache size to 53*1000=53,000 entries using a least recently used algorithm -->
<bean id="Evictor" className="com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor">
<property name="numberOfLRUQueues" type="int" value="53" description="set number of LRU queues" />
<property name="maxSize" type="int" value="1000" description="set max size for each LRU queue" />
</backingMapPluginCollection>
</backingMapPluginCollections>
</objectGridConfig>
Use the following code snippet to programmatically configure an LRU evictor for the near cache. Your override must specify either the default map name that corresponds to your data grid name or one of the template map names. For more information about the template map names, see Dynamic map configuration options. For example, the following sample configures a least recently used (LRU) evictor for all maps based on the *.NONE.NCI template map definition:
ObjectGridConfiguration companyGridConfig = ObjectGridConfigFactory
.createObjectGridConfiguration("CompanyGrid");
BackingMapConfiguration customerMapConfig = ObjectGridConfigFactory
.createBackingMapConfiguration(".*\\.NONE\\.NCI");
Plugin evictorPlugin = ObjectGridConfigFactory.createPlugin(PluginType.EVICTOR,
"com.ibm.websphere.objectgrid.plugins.builtins.LRUEvictor");
ConfigProperty numQueues=ObjectGridConfigFactory.createConfigProperty(ConfigPropertyType.INT_PRIM,
"numberOfLRUQueues", "53");
evictorPlugin.addConfigProperty(numQueues);
ConfigProperty maxSize=ObjectGridConfigFactory.createConfigProperty(ConfigPropertyType.INT_PRIM,
"maxSize", "1000");
evictorPlugin.addConfigProperty(maxSize);
customerMapConfig.addPlugin(evictorPlugin);
companyGridConfig.addBackingMapConfiguration(customerMapConfig);
ClientClusterContext client = ogManager.connect(catalogServerEndpoints, null, null);
ObjectGrid companyGrid = ogManager.getObjectGrid(client, objectGridName,companyGridConfig);