此内容没有您所选择的语言版本。
7.2.2. Adding and Replacing a Key Value
Red Hat JBoss Data Grid offers a thread-safe data structure.
The following procedure is an example that defines what each line entered into the
DefaultCacheQuickstart.java file does:
Procedure 7.3. Adding and Replacing a Key Value
- Add an entry
keywithvalueas the key's value.cache.put("key", "value");
Procedure 7.4. Replacing a Key Value
- The following code searches for keys (named
keyandkey2). If the two specific keys beings searched for are not found, JBoss Data Grid creates two new keys with the specified key names and values.cache.putIfAbsent("key", "newValue"); cache.putIfAbsent("key2", "value2"); - The following code confirms that the value of the stored key equals the value we wanted to store.
assertEquals(cache.get("key"), "value"); assertEquals(cache.get("key2"), "value2");
See Also: