可能是由于 Ignite 缓存大于可用内存而导致的问题。您可以通过使用 Eviction Policy(淘汰策略)来限制缓存大小,并从缓存中删除较旧的键/值对。以下是使用 LRU(最近最少使用)策略的示例代码:
// Create Ignite Cache configuration with eviction policy.
CacheConfiguration cacheCfg = new CacheConfiguration("myCache");
cacheCfg.setEvictionPolicy(new LruEvictionPolicy(100000));
// Create Ignite Cache instance with above configuration.
Ignite ignite = Ignition.start();
IgniteCache cache = ignite.getOrCreateCache(cacheCfg);
// Put some data into cache.
cache.put("key1", "value1");
// Query cache.
QueryCursor> cursor = cache.query(new ScanQuery());
for (Map.Entry entry : cursor) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
在上面的示例中,我们使用了 LRU 策略限制了缓存大小为 100,000。当缓存大小达到此限制时,Ignite 将根据最近使用时间删除队列中的最老键/值对。这样,就可以避免上述问题。