我正在使用 ignite 缓存,我想缓存一个 id 不相关的 View ,因此当没有 id 时,实现 loadCache
对我来说似乎有些棘手!!!
我应该如何更新下面的示例
public class CacheJdbcPersonStore extends CacheStoreAdapter<Long, Person> {
...
// This method is called whenever "IgniteCache.loadCache()" or
// "IgniteCache.localLoadCache()" methods are called.
@Override public void loadCache(IgniteBiInClosure<Long, Person> clo, Object... args) {
if (args == null || args.length == 0 || args[0] == null)
throw new CacheLoaderException("Expected entry count parameter is not provided.");
final int entryCnt = (Integer)args[0];
Connection conn = null;
try (Connection conn = connection()) {
try (PreparedStatement st = conn.prepareStatement("select * from PERSONS")) {
try (ResultSet rs = st.executeQuery()) {
int cnt = 0;
while (cnt < entryCnt && rs.next()) {
Person person = new Person(rs.getLong(1), rs.getString(2), rs.getString(3));
clo.apply(person.getId(), person);
cnt++;
}
}
}
}
catch (SQLException e) {
throw new CacheLoaderException("Failed to load values from cache store.", e);
}
}
...
}
clo.apply(person.getId(), person);
这部分是我的逻辑问题,我的 View 没有 ID
最佳答案
您需要一些唯一的 ID 来在 Ignite 中存储数据。如果实际数据中没有合适的内容,您的选择是:
UUID.randomUUID()
- 简单计数器 (
id++
) 或LongAdder
/AtomicLong
- 仅当您从单个节点加载时才有效 IgniteAtomicSequence
- 适用于整个集群
关于java - 实现cacheStore时没有ID时如何加载数据来点燃缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58910407/