---
title:  Managing a Peer or Server Cache
---

<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.  See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

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

<a id="creating_and_closing_a_peer_cache__section_1633A80F0DB04794BB6C3A7F05EED97E"></a>
<%=vars.product_name%> peers are members of a <%=vars.product_name%> cluster that do not act as clients to another <%=vars.product_name%> cluster. <%=vars.product_name%> servers are peers that also listen for and process client requests.

1.  Create your cache:
    1.  Start up a cluster and the cluster configuration service:
        1.  Start a locator with `--enable-cluster-configuration` set to true. (It is set true by default.)

            ``` pre
            gfsh>start locator --name=locator1
            ```

        2.  Start up member processes that use the cluster configuration service (enabled by default):

            ``` pre
            gfsh>start server --name=server1 --server-port=40404
            ```

        3.  Create regions:

            ``` pre
            gfsh>create region --name=customerRegion --type=REPLICATE

            gfsh>create region --name=ordersRegion --type=PARTITION
            ```

    2.  Or if you are not using the cluster configuration service, directly configure cache.xml in each member of your cluster. In your `cache.xml`, use the `cache` DOCTYPE and configure your cache inside a `<cache>` element. Example:

        ``` pre
        <?xml version="1.0" encoding="UTF-8"?>
        <cache
            xmlns="http://geode.apache.org/schema/cache"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://geode.apache.org/schema/cache http://geode.apache.org/schema/cache/cache-1.0.xsd"
            version="1.0”>
            // 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>
        ```

    3.  To programmatically create the `Cache` instance:
        -   In your Java application, use the `CacheFactory` create method:

            ``` pre
            Cache cache = new CacheFactory().create();
            ```
        -   If you are running a server using the <%=vars.product_name%> `cacheserver` process, it automatically creates the cache and connection at startup and closes both when it exits.

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

2.  Close your cache when you are done using the inherited `close` method of the `Cache` instance:

    ``` pre
    cache.close();
    ```


