6.2. Local Mode


Using Red Hat JBoss Data Grid's local mode instead of a map provides a number of benefits.
Caches offer features that are unmatched by simple maps, such as:
  • Write-through and write-behind caching to persist data.
  • Entry eviction to prevent the Java Virtual Machine (JVM) running out of memory.
  • Support for entries that expire after a defined period.
JBoss Data Grid is built around a high performance, read-based data container that uses techniques such as optimistic and pessimistic locking to manage lock acquisitions.
JBoss Data Grid also uses compare-and-swap and other lock-free algorithms, resulting in high throughput multi-CPU or multi-core environments. Additionally, JBoss Data Grid's Cache API extends the JDK's ConcurrentMap, resulting in a simple migration process from a map to JBoss Data Grid.

6.2.1. Configure Local Mode (Remote Client-Server Mode)

A local cache can be added to any cache container. The following example demonstrates how to add the local-cache element.

Procedure 6.2. The local-cache Element

The local-cache element specifies information about the local cache used with the cache container using the following parameters:
  1. Add the Local Cache Name

    The name parameter specifies the name of the local cache to use.
    <cache-container name="local"
                      default-cache="default" 
                      statistics="true">
             <local-cache name="default" >
  2. Set the Cache Container Start Mode

    The start parameter indicates when the cache container starts, i.e. whether it will start lazily when requested or "eagerly" when the server starts up. Valid values for this parameter are EAGER and LAZY.
    <cache-container name="local"
                      default-cache="default" 
                      statistics="true">
             <local-cache name="default"
                              start="EAGER" >
  3. Configure Batching

    The batching parameter specifies whether batching is enabled for the local cache.
    <cache-container name="local"
                      default-cache="default"
                      statistics="true">
             <local-cache name="default"
                              start="EAGER"
                              batching="false" >
  4. Per-cache Statistics

    If statistics are enabled at the container level, per-cache statistics can be selectively disabled for caches that do not require monitoring by setting the statistics attribute to false.
    <cache-container name="local"
                      default-cache="default"
                      statistics="true">
             <local-cache name="default"
                              start="EAGER"
                              batching="false"
                              statistics="true">
  5. Specify Indexing Type

    The indexing parameter specifies the type of indexing used for the local cache. Valid values for this parameter are NONE, LOCAL and ALL.
    <cache-container name="local"
                      default-cache="default" 
                      statistics="true">
             <local-cache name="default"
                              start="EAGER"
                              batching="false"
                              statistics="true">
                      <indexing index="NONE">
    	                <property name="default.directory_provider">ram</property>
                      </indexing>
             </local-cache>
Alternatively, create a DefaultCacheManager with the "no-argument" constructor. Both of these methods create a local default cache.
Local and clustered caches are able to coexist in the same cache container, however where the container is without a <transport/> it can only contain local caches. The container used in the example can only contain local caches as it does not have a <transport/>.
The cache interface extends the ConcurrentMap and is compatible with multiple cache systems.

6.2.2. Configure Local Mode (Library Mode)

In Red Hat JBoss Data Grid's Library mode, setting a cache's mode parameter to local equals not specifying a clustering mode at all. In the case of the latter, the cache defaults to local mode, even if its cache manager defines a transport.
Set the cluster mode to local as follows:
<clustering mode="local" />
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.