Infinispan 8 - cache.clear() - 如何正确理解 javadoc?

Infinispan 8 - cache.clear() - How to understand the javadoc correctly?

在 infinispan 8.2.5.Final 我有一个用例,我想 evict/clear 缓存中的所有条目。我正在调用 cache.clear()。 Javadoc 说:

void org.infinispan.Cache.clear()

Removes all mappings from the cache.

Note: This should never be invoked in production unless you can guarantee no other invocations are ran concurrently.

If the cache is transactional, it will not interact with the transaction.

Specified by: clear() in Map

是否意味着"no other invocations of cache.clear()"?或者它的意思是 "no other invocations of the underlying cache at all"?所以没有 cache.put 和 cache.get 同时存在?

清除缓存(新数据传入)是一个常见的用例。我用错方法了吗?是否有其他方法可以从 infinispan 缓存中逐出所有项目?

编辑: 我 运行 我的缓存处于失效模式。 clear() 操作是使所有节点中的所有条目无效还是仅使本地节点中的条目无效?

表示"no other write operation can be run"。 clear() 可能会破坏并发写操作(它可以在某些节点中应用,但在另一个节点中丢失),因为它不会尝试获取任何锁定。

如果担心并发写入,可以使用stream()或者iterator()。例如:

cache.keySet().stream().forEach(BasicCache::remove);

for (Iterator<K> it = cache.keySet().iterator(); it.hasNext(); ) {
    it.next();
    it.remove();
}

应该可以解决问题。