Managing a Peer or Server Cache

You start your peer or server cache using a combination of XML declarations and API calls. Close the cache when you are done.

GemFire peers are members of a GemFire distributed system that do not act as clients to another GemFire distributed system. GemFire servers are peers that also listen for and process client requests.
  1. Create your cache:
    1. In your cache.xml, use the cache DOCTYPE and configure your cache inside a <cache> element. Example:
      <!DOCTYPE cache PUBLIC
       	"-//GemStone Systems, Inc.//GemFire Declarative Caching 7.0//EN" 
      "http://www.gemstone.com/dtd/cache7_0.dtd">
      <cache>
      	// NOTE: Use this <cache-server> element only for server processes 
      	<cache-server port="40404"/>
      
      	<region name="customerRegion" refid="REPLICATE" />
      	<region name="ordersRegion" refid="PARTITION" />
      </cache>
    2. Create the Cache instance:
      • In your Java application, use the CacheFactory create method:
        Cache cache = new CacheFactory().create();
      • If you are running a server using the GemFire gfsh start server process, it automatically creates the cache and connection at startup and closes both when it exits.

      The system creates the distributed system connection and initializes the cache according to your gemfire.properties and cache.xml specifications.

  2. Close your cache when you are done using the close method of your Cache instance:
    cache.close();