blob: 66accee1a4ef99674491cf5d0f440b3ac774467b [file] [log] [blame]
---
title: Adding an Entry to the 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 can populate a client region with cache entries using the `Region::put` or the `Region::create` API functions.
The `put` function places a new value into a region entry with the specified key, while the `create` function creates a new entry in the region. Both functions provide a user-defined parameter object to any cache writer invoked in the process, and new values for both functions are propagated to a connected cache server.
## Adding Entries Using create
When the put function adds an entry, the previous value is overwritten if there is already an entry associated with the specified key in the region. In this example, the program uses the API to put 100 entries into the cache by iteratively creating keys and values, both of which are integers.
``` pre
for ( int32_t i=0; i < 100; i++ ) {
regionPtr->put( i, CacheableInt32::create(i) );
}
```
## <a id="concept_26D4E6C6BC6F4AB8884E33119999656D__section_748916759F0246619CD27E7456DCA365" class="no-quick-link"></a>Bulk Put Operations Using putAll
You can batch up multiple key/value pairs into a hashmap and put them into the cache with a single operation using the `Region::putAll` API function. Each entry is processed for interest registration on the server, so each entry requires its own unique event ID. Updates and creates can be mixed in a `putAll` operation, so those events need to be addressed on the cache server for appropriate cache listener invocation on distributed system members. Map entries retain their original order when they are processed at the server.
The following table lists the client and cache server statistics for `putAll`.
<a id="concept_26D4E6C6BC6F4AB8884E33119999656D__table_4693B08B5B4D44118DC399C8826C9750"></a>
| Statistic Type | Chart Name | Description |
|--------------------|---------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `CachePerfStats` | `Putalls` | Total number of times a map is added or replaced in the cache as a result of a local operation. Also reports the number of `putAll` operations. |
| `CachePerfStats` | `putallTime` | Total time to replace a map in the cache as a result of a local operation. |
| `CacheServerStats` | `putAllRequests` | Number of `putAll` requests. |
| `CacheServerStats` | `putAllResponses` | Number of `putAll` responses written to the cache client. |
| `CacheServerStats` | `processPutAllTime` | Total time to process a cache client `putAll` request, including the time to put all objects into the cache. |
| `CacheServerStats` | `readPutAllRequestTime` | Total time to read `putAll` requests. |
| `CacheServerStats` | `writePutAllResponseTime` | Total time to write `putAll` responses. |
| `CacheClientStats` | `putAll` | Number of `putAll` requests sent to the cache server. |
| `CacheClientStats` | `sendPutAllTime` | Total time for `sendPutAll` . |
<span class="tablecap">**Table 1.** putAll Statistics for Cache Server and Client</span>
The `putAll` function also supports providing a callback argument to any cache loaders or cache writers that are invoked in the operation.