Cache Initialization File (cache.xml)

To ease the task of managing the structure of the cache, you can define the default GemFire cache structure in an XML-based initialization file.

Cache Initialization File Basics

The contents of the cache initialization file are used to populate or update a cache.

This occurs when a cache server starts up, when a client application explicitly creates its cache, or when a client explicitly loads a new structure into an existing cache.

The initialization file can have any name, but is generally referred to as cache.xml. Both client applications and cache servers can use an optional cache.xml file to ease the initialization process.

File Contents

The contents of a declarative XML file correspond to APIs declared in the Cache.hpp and Region.hpp header files. The cache initialization file allows you to accomplish declaratively many of the cache management activities that you can program through the API.

  • The contents of the cache initialization file must conform to the XML definition in http://geode.apache.org/schema/cache/cache-1.0.xsd. This file identifies the valid element tags that may be present in your XML file, the attributes that correspond to each element, and the valid values for the elements and attributes.
  • The name of the declarative XML file is specified when establishing a connection to the distributed system. You can define it by setting the cache-xml-file configuration attribute in the geode.properties file for the client. For details about the geode.properties file, see Setting System and Cache Properties.

Example cache.xml File

An example cache.xml file shows cache and region initialization for a client, presenting a subset of the possible data configurations.

Specific information about cache and region attributes is in Region Attributes.

For information on using a cache with a server pool, see Using Connection Pools. The example below shows a cache.xml file that creates a region.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE cache PUBLIC
    "-//Example Systems, Inc.//Example Declarative Caching 1.0//EN"
    "http://geode.apache.org/schema/cache/cache-1.0.xsd">
<!-- Sample cache.xml file -->
<!-- Example Declarative Cache Initialization with cache.xml -->
<cache>
    <pool name="examplePool" subscription-enabled="true">
        <server host="localhost" port="24680" />
    </pool>
    <region name="root1" refid="CACHING_PROXY">
        <region-attributes pool-name="examplePool"
            initial-capacity="25"
            load-factor="0.32"
            concurrency-level="10"
            lru-entries-limit="35">
            <region-idle-time>
                <expiration-attributes timeout="20" action="destroy"/>
            </region-idle-time>
            <entry-idle-time>
                <expiration-attributes timeout="10" action="invalidate"/>
            </entry-idle-time>
            <region-time-to-live>
                <expiration-attributes timeout="5" action="local-destroy"/>
            </region-time-to-live>
            <entry-time-to-live>
                <expiration-attributes timeout="10" action="local-invalidate"/>
            </entry-time-to-live>
        </region-attributes>
    </region>
</cache>