此内容没有您所选择的语言版本。

Chapter 46. Near Caching


46.1. Near Caching

Near caches are optional caches for Hot Rod Java client implementations that keep recently accessed data close to the user, providing faster access to data that is accessed frequently. This cache acts as a local Hot Rod client cache that is updated whenever a remote entry is retrieved via get or getVersioned operations.

Important

Near Caching for Library mode, or non-Hot Rod interfaces, is achieved by configuring L1 Caches. Configuring L1 Caches are documented in the JBoss Data Grid Administration and Configuration Guide .

In Red Hat JBoss Data Grid, near cache consistency is achieved by using remote events, which send notifications to clients when entries are modified or removed (refer to Remote Event Listeners (Hot Rod)). With Near Caching, local cache remains consistent with remote cache. Local entry is updated or invalidated whenever remote entry on the server is updated or removed. At the client level, near caching is configurable as either of the following:

  • DISABLED - the default mode, indicating that Near Caching is not enabled.
  • INVALIDATED - enables near caching, keeping it in sync with the remote cache via invalidation messages.
Note

Near caching is disabled for Hot Rod clients by default.

Figure 46.1. Near Caching Architecture

46.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 as INVALIDATED 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 near caching:

Enabling a Near Cache

import org.infinispan.client.hotrod.configuration.ConfigurationBuilder;
import org.infinispan.client.hotrod.configuration.NearCacheMode;
…

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.nearCache().mode(NearCacheMode.INVALIDATED).maxEntries(100);
Copy to Clipboard Toggle word wrap

A maximum size for the near cache must be provided, using the maxEntries(int maxEntries) method. In the above example this is defined to 100. When the maximum size is reached, near cached entries are evicted using a least-recently-used (LRU) algorithm. To define an unlimited near cache, a 0 or negative value may be passed in.

46.3. Near Caches in a Clustered Environment

Near caches are implemented using Hot Rod Remote Events, and utilize clustered listeners for receiving events from across the cluster. Clustered listeners are installed on a single node within the cluster, with the remaining nodes sending events to the node on which the listeners are installed. It is therefore possible for a node running the near cache-backing clustered listener to fail. In this situation, another node takes over the clustered listener.

When the node running the clustered listener fails, a client failover event callback can be defined and invoked. For near caches, this callback and its implementation will clear the near cache, as during a failover events may be missed.

Refer to Clustered Listeners for more information.

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat