Creating and Accessing a Cache

When you create a client cache, you are creating a client cache instance. You must provide some basic configuration information such as a connection name and cache initialization parameters for the client’s cache instance.

When you create a cache, you provide the following input:

  • Connection name. Used in logging to identify both the distributed system connection and the cache instance. If you do not specify a connection name, a unique (but non-descriptive) default name is assigned.
  • cache.xml to initialize the cache (if the initialization is not done programmatically). To modify the cache structure, edit cache.xml in your preferred text editor. No changes to the application code are required. If you do not specify a cache.xml file, you need to initialize the cache programmatically.

The cache.xml file contains XML declarations for cache, region, and region entry configuration.

This XML declares server connection pools and regions:

  <region name="clientRegion1" refid="PROXY">
    <region-attributes pool-name="serverPool1"/>
  <region name="clientRegion2" refid="PROXY">
    <region-attributes pool-name="serverPool2"/>
  <region name="localRegion3" refid="LOCAL"/>
  <pool name="serverPool1">
    <locator host="host1" port="40404"/>
  <pool name="serverPool2">
    <locator host="host2" port="40404"/>

When you use the regions, the client regions connect to the servers through the pools named in their configurations.

This file can have any name, but is generally referred to as cache.xml .

For a list of the parameters in the cache.xml file, including the XSD, see Cache Initialization File.

To create your cache, call the CacheFactory create function. The cache object it returns gives access to the client caching API. For example:

CacheFactoryPtr cacheFactory = CacheFactory::createCacheFactory();
CachePtr cachePtr = cacheFactory->create();

Note: For more information on how to create a cache for C++ clients, see Creating a Cache, or for .NET clients, see Creating a Cache.