[Java programming language only]

Configuring the near cache

You can configure your clients to have a local, in-line cache. This optional cache is called a near cache, an independent data grid on each client, serving as a cache for the remote, server-side cache. The near cache is enabled by default when locking is disabled, or is configured as optimistic, and cannot be used when configured as pessimistic.

Before you begin

You must create a simple data grid in the user interface. See Creating simple data grids for more information.

About this task

A near cache is fast because it provides local in-memory access to a subset of the entire cached data set that is stored remotely.

Procedure

  1. You can enable a near cache to be created on the client by setting the dynamic map name. You must set the dynamic map to have optimistic locking or no locking. Examples of map names that have a near-cache enabled follow:
    my_grid.NONE
    my_grid.NONE.O
    For more information, see Configuring dynamic maps. For a list of dynamic map configuration options, see Dynamic map configuration options.
  2. [Version 2.5.0.4 and later] Set the nearCacheCopyMode copy mode in the ObjectGrid descriptor XML file, or set the copy mode programmatically using the BackingMapConfiguration.setNearCacheCopyMode method. You can set the copy mode to nearCacheCopyMode only if the server is COPY_TO_BYTES or COPY_TO_BYTES_RAW. The copy mode is disabled by default; for example:

    XML file example

    backingMap name="default" nearCacheCopyMode="NO_COPY" readOnly="true" /

    Programmatic example

    ObjectGridConfiguration copyModeConfig = ObjectGridConfigFactory.createObjectGridConfiguration("copyModeGrid");
    BackingMapConfiguration defaultMapConfig = ObjectGridConfigFactory.createBackingMapConfiguration("default");
    	        defaultMapConfig.setNearCacheCopyMode(CopyMode.NO_COPY);
    	        defaultMapConfig.setReadOnly(true);
    	        copyModeConfig.addBackingMapConfiguration(defaultMapConfig);

Results

To check whether a near cache is enabled, run the BackingMap.isNearCacheEnabled() method in your client. You can also look for the CWOBJ1128I message in the log files on the client to see if the near cache is enabled.

What to do next

By default, the client-side near cache does not have a maximum size and out of memory errors in the client can occur. To control the size of the near cache, configure a client-side override that enables a time-to live (TTL) or least recently used (LRU) evictor on the client. For more information about configuring an evictor for the near cache, see Configuring an evictor for the near cache.