3.3. Using Eviction
eviction/> element is used to enable eviction without any strategy or maximum entries settings, the following default values are automatically implemented:
- Strategy: If no eviction strategy is specified,
EvictionStrategy.NONEis assumed as a default.
- max-entries/maxEntries: If no value is specified, the
max-entries/maxEntries value is set to
-1, which allows unlimited entries.
3.3.1. Initialize Eviction
max-entriesattributes value to a number greater than zero. Adjust the value set for
max-entriesto discover the optimal value for your configuration. It is important to remember that if too large a value is set for
max-entries, Red Hat JBoss Data Grid runs out of memory.
Procedure 3.1. Initialize Eviction
Add the Eviction TagAdd the <eviction> tag to your project's <cache> tags as follows:
Set the Eviction StrategySet the
strategyvalue to set the eviction strategy employed. Possible values are
NONEif no eviction is required). The following is an example of this step:
<eviction strategy="LRU" />
Set the Maximum EntriesSet the maximum number of entries allowed in memory. The default value is
-1for unlimited entries.
- In Library mode, set the
maxEntriesparameter as follows:
<eviction strategy="LRU" maxEntries="200" />
- In Remote Client Server mode, set the
<eviction strategy="LRU" max-entries="200" />
Eviction is configured for the target cache.
3.3.2. Eviction Configuration Examples
- A sample XML configuration for Library mode is as follows:
<eviction strategy="LRU" maxEntries="2000"/>
- A sample XML configuration for Remote Client Server Mode is as follows:
<eviction strategy="LRU" max-entries="20"/>
- A sample programmatic configuration for Library Mode is as follows:
Configuration c = new ConfigurationBuilder().eviction().strategy(EvictionStrategy.LRU) .maxEntries(2000) .build();
maxEntriesparameter while Remote Client-Server mode uses the
max-entriesparameter to configure eviction.
3.3.3. Changing the Maximum Entries Value at Runtime
- Invoking the setMaxEntries operation sets maximum number of entries in the data container.
- If the data container does not support eviction, setting it will raise an exception.
- Defining a value less than 0 will throw an error.
3.3.4. Eviction Configuration Troubleshooting
max-entriesparameter of the
evictionelement. This is because although the
max-entriesvalue can be configured to a value that is not a power of two, the underlying algorithm will alter the value to
Vis the closest power of two value that is larger than the
max-entriesvalue. Eviction algorithms are in place to ensure that the size of the cache container will never exceed the value