2.4.4 Replacing data (using replace)
You use replace to replace data in a cache.
While put unconditionally updates values, replace replaces values only when they match the specified values.
The following figure shows an example in which a value whose key is 001 is replaced with BBBB.
This example replaces the value with BBBB because it matches the specified value (AAAA).
- Reference note
-
Difference between put and replace
To check the contents of a stored value and then update the value, you might use get to obtain a value, an application program checks the value, and then you execute put. However, the value might be updated by another application program between the get and put processes. You can avoid this problem by using replace.
The following figure shows the difference between put and replace by means of an example that replaces ABC with DEF.