2.6. 强制返回值
为了避免不必要地发送数据,对远程缓存写入操作会返回 null
,而不是之前的值。
例如,以下方法调用不会返回键以前的值:
V remove(Object key); V put(K key, V value);
V remove(Object key);
V put(K key, V value);
但是,您可以更改默认行为,以便您的调用返回之前的密钥的值。
流程
- 配置 Hot Rod 客户端,以便方法调用以以下一种方式之一返回键以前的值:
FORCE_RETURN_VALUE 标记
cache.withFlags(Flag.FORCE_RETURN_VALUE).put("aKey", "newValue")
cache.withFlags(Flag.FORCE_RETURN_VALUE).put("aKey", "newValue")
per-cache
ConfigurationBuilder builder = new ConfigurationBuilder(); // Return previous values for keys for invocations for a specific cache. builder.remoteCache("mycache") .forceReturnValues(true);
ConfigurationBuilder builder = new ConfigurationBuilder();
// Return previous values for keys for invocations for a specific cache.
builder.remoteCache("mycache")
.forceReturnValues(true);
hotrod-client.properties
Use the "*" wildcard in the cache name to return previous values for all caches that start with the "somecaches" string.
# Use the "*" wildcard in the cache name to return previous values
# for all caches that start with the "somecaches" string.
infinispan.client.hotrod.cache.somecaches*.force_return_values = true