Example For Bulk Load #588
-
I would really appreciate if you can show how to override the loadAll in cache loader? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @gyansatapathy, You can simply implement the method and the cache will invoke it on a bulk request. Cache<UUID, User> users = Caffeine.newBuilder().build(new CacheLoader<UUID, User>() {
public User load(UUID id) {
return repository.getUserById(id);
}
public Map<UUID, User> loadAll(Set<UUID> ids) {
return repository.getAllUsersById(ids);
}
});
cache.get(Set.of(UUID.randomUUID(), UUID.randomUUID())); You might also find the Cache<UUID, User> users = Caffeine.newBuilder()
.build(CacheLoader.bulk((Set<UUID> keys) -> repository.getAllUsersById(ids));
cache.get(Set.of(UUID.randomUUID(), UUID.randomUUID())); |
Beta Was this translation helpful? Give feedback.
-
Hi @ben-manes I found out there was an issue in my classpath due to spring dependency management plugin as it was forcing an older version. Its working now. Thanks a ton. |
Beta Was this translation helpful? Give feedback.
Hi @gyansatapathy,
You can simply implement the method and the cache will invoke it on a bulk request.
You might also find the
CacheLoader.bulk
convenience function useful as a shorter syntax that delegatesload(key)
to theloadAll(keys)
method.