Show Table of Contents
35.2. Configuring Near Caches
Near caching can be enabled and disabled via configuration without making any changes to the Hot Rod Client application. To enable near caching, configure the near caching mode (Eager or Lazy) on the client and optionally specify the number of entries to be kept in the cache.
Near cache mode is configured using the
NearCacheMode enumeration.
The following example demonstrates how to configure Lazy near cache mode.
Example 35.1. Configuring Lazy Near Cache Mode
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.configuration.NearCacheMode; … ConfigurationBuilder lazy = new ConfigurationBuilder(); lazy.nearCache().mode(NearCacheMode.LAZY).maxEntries(10);
The following example demonstrates how to configure Eager near cache mode.
Example 35.2. Configuring Eager Near Cache Mode
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; import org.infinispan.client.hotrod.configuration.NearCacheMode; ... ConfigurationBuilder eager = new ConfigurationBuilder(); eager.nearCache().mode(NearCacheMode.EAGER)..maxEntries(10);
Note
Near cache size is unlimited by default but it can be changed to set a maximum size in terms of number of entries for the near cache. When the maximum size is reached, near cached entries are evicted using a least-recently-used (LRU) algorithm.
Example 35.3. Configuring Near Cache Maximum Size
import org.infinispan.client.hotrod.configuration.ConfigurationBuilder; ... ConfigurationBuilder builder = new ConfigurationBuilder(); builder.nearCache().maxEntries(100);
Here, 100 is the maximum number of entries to keep in the near cache.
Note
This configuration also results in a disabled near cache mode when no mode is specified.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.