LATEST VERSION: 8.1.0 - CHANGELOG
Pivotal GemFire® v8.1

Cache Eviction Example

Cache Eviction Example

Eviction controls your data region size by removing least recently used (LRU) entries to make way for new data.

You can use eviction to control how much heap your data regions use. It kicks in when your data region reaches a specified size or entry count. Size can be absolute or a percentage of your application's current heap.

Running the Example

In this example, the data region is configured to keep the entry count at 10 or below by destroying LRU entries. A cache listener installed on the region reports the changes to the region entries.

Note: To run this example, you must have terminal sessions configured for the QuickStart examples, as described in Setting Up Your Environment for Running the Examples.

In a single session, run the example:

$ java -cp "$GEMFIRE/SampleCode/quickstart/classes:$GEMFIRE/lib/server-dependencies.jar" quickstart.DataEviction

Example Source Files

Program and cache configuration source files for the example, including the listener declared in the DataEviction.xml file:

Table 1. Cache configuration files, located in SampleCode//quickstart/xml
DataEviction.xml Configures a region to destroy entries when the region reaches a certain capacity. Includes a listener to report on the activity.
Table 2. Java program files, located in SampleCode//quickstart/quickstart
DataEviction.java Demonstrates data eviction by adding more entries than the cache is configured to hold.
SimpleCacheListener.java A CacheListener that reports cache events.
Related Topics
Eviction

Related Javadocs

  • com.gemstone.gemfire.cache.EvictionAttributes