Introduction to Cache Management
The cache provides in-memory storage and management for your data.
You organize your data in the cache into data regions, each with its own configurable behavior. You store your data into your regions in key/value pairs called data entries. The cache also provides features like transactions, data querying, disk storage management, and logging. See the Javadocs for
You generally configure caches using the
gfsh command-line utility or a combination of XML declarations and API calls. GemFire loads and processes your XML declarations when you first create the cache.
GemFire has one cache type for managing server and peer caches and one for managing client caches. The cache server process automatically creates its server cache at startup. In your application process, the cache creation returns an instance of the server/peer or client cache. From that point on, you manage the cache through API calls in your application.
GemFire’s caching APIs provide specialized behavior for different system member types and security settings.
org.apache.geode.cache.RegionService. Generally, you use the
RegionServicefunctionality through instances of
ClientCache. You only specifically use instances of
RegionServicefor limited-access users in secure client applications that service many users. The
RegionServiceAPI provides access to existing cache data regions and to the standard query service for the cache. For client caches, queries are sent to the server tier. For server and peer caches, queries are run in the current cache and any available peers.
RegionServiceis implemented by
org.apache.geode.cache.GemFireCache. You do not specifically use instances of
GemFireCache, but you use
GemFireCachefunctionality in your instances of
RegionServiceand adds general caching features like region attributes, disk stores for region persistence and overflow, and access to the underlying cluster.
GemFireCacheis implemented by
org.apache.geode.cache.Cache. Use the
Cacheinterface to manage server and peer caches. You have one
Cacheper server or peer process. The
GemFireCacheand adds server/peer caching features like communication within the cluster, region creation, transactions and querying, and cache server functionality.
org.apache.geode≈setting_cache_initializer.cache.ClientCache. Use the
ClientCacheinterface to manage the cache in your clients. You have one
ClientCacheper client process. The
GemFireCacheand adds client-specific caching features like client region creation, subscription keep-alive management for durable clients, querying on server and client tiers, and RegionService creation for secure access by multiple users within the client.
cache.xml must be formatted according to the product XML schema definition
cache-1.0.xsd. The schema definition file is available at
You use one format for peer and server caches and another for client caches.
cache.xml for Peer/Server:
<?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”> ... </cache>
cache.xml for Client:
<?xml version="1.0" encoding="UTF-8"?> <client-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”> ... </client-cache>
For more information on the
cache.xml file, see cache.xml.
Your system configuration and cache configuration are initialized when you start your member processes and create each member’s GemFire cache. If you are using the cluster configuration service, member processes can pick up its cache configuration from the cluster or group’s current configuration. See Overview of the Cluster Configuration Service.
The steps in this section use
cache.xml file examples, except where API is required. You can configure your cluster properties and cache through the API as well, and you can use a combination of file configuration and API configuration.
The XML examples may not include the full
cache.xml file listing. All of your declarative cache configuration must conform to the cache XSD at
For all of your GemFire applications:
- Create your
Cache, for peer/server applications, or
ClientCache, for client applications. This connects to the GemFire system you have configured and initializes any configured data regions. Use your cache instance to access your regions and perform your application work.
- Close your cache when you are done. This frees up resources and disconnects your application from the cluster in an orderly manner.
Follow the instructions in the subtopics under Cache Management to customize your cache creation and closure for your application needs. You may need to combine more than one of the sets of instructions. For example, to create a client cache in a system with security, you would follow the instructions for creating and closing a client cache and for creating and closing a cache in a secure system.
To aid in the administration of cache data and speed the setup of new environments, you can export a snapshot of the entire cache (all regions) and then import the snapshot into a new cache. For example, you could take a snapshot of the production environment cache in order to import the cache’s data into a testing environment.
For more details on exporting and importing snapshots of a cache, see Cache and Region Snapshots.
Cache Management with gfsh and the Cluster Configuration Service
You can use gfsh commands to mange a server cache. There are gfsh commands to create regions, start servers, and to create queues and other objects. As you issue these commands, the Cluster Configuration Service saves cache.xml and gemfire.properties files on the locators and distributes those configurations to any new members that join the cluster. See Overview of the Cluster Configuration Service.