PRODUCTS AND SERVICES INDUSTRIES SUPPORT PARTNERS COMMUNITIES ABOUT
  Coherence 3.4 User Guide
  Configuring a Near Cache for C++ Clients
Added by Rob Misek, last edited by Tom Pfaeffle on Aug 20, 2008  (view change)

Labels

 

This section describes the Near Cache as it pertains to Coherence for C++ clients. For a complete discussion of the concepts behind a Near Cache, its configuration, and ways to keep it in sync with the back tier see Near Cache in the User Guide.

In Coherence for C++, the Near Cache is a coherence::net::NamedCache implementation that wraps the front cache and the back cache using a read-through/write-through approach. If the back cache implements the ObservableCache interface, then the Near Cache can use either of the Listen None, Listen Present, Listen All, or Listen Auto strategy to invalidate any front cache entries that might have been changed in the back cache.

A typical Near Cache is configured to use a Local Cache (thread safe, highly concurrent, size-limited and/or auto-expiring local cache) as the front cache and a remote cache as a back cache. A Near Cache is configured via the near-scheme which has two child elements - a front-scheme for configuring a local (front) cache and a back-scheme for defining a remote (back) cache.

Configuring the Near Cache

A Near Cache is configured by using the <near-scheme> element in the coherence-cache-config file. This element has two required sub-elements: front-scheme for configuring a local (front-tier) cache and a back-scheme for defining a remote (back-tier) cache. While a local cache (<local-scheme>) is a typical choice for the front-tier, you can also use schemes based on Java objects (<class-scheme>) and, other than for .Net and C++ clients, non-JVM heap based caches (<external-scheme> or <paged-external-scheme>).

The remote or back-tier cache is described by the <back-scheme> element. A back-tier cache can be either a distributed cache (<distributed-scheme>) or a remote cache (<remote-cache-scheme>). The <remote-cache-scheme> element allows you to use a clustered cache from outside the current cluster.

Optional sub-elements of <near-scheme> include <invalidation-strategy> for specifying how the front-tier and back-tier objects will be kept in sync and <listener> for specifying a listener which will be notified of events occurring on the cache.

For an example configuration, see Sample Near Cache Configuration. The elements in the file are described in the <near-scheme> topic.

Obtaining a Near Cache Reference with C++

A reference to a configured Near Cache can be obtained by name by using the coherence::net::CacheFactory class:

NamedCache::Handle hCache = CacheFactory::getCache("example-near-cache");
Cleaning up the resources associated with a NearCache

Instances of all NamedCache implementations, including NearCache, should be explicitly released by calling the NamedCache::release() method when they are no longer needed, in order to free up any resources they might hold.

If the particular NamedCache is used for the duration of the application, then the resources will be cleaned up when the application is shut down or otherwise stops. However, if it is only used for a period of time, the application should call its release() method when finished using it.