Skip to content

Thoughts on a 3.x breaking change

Brad Baker edited this page Mar 4, 2020 · 2 revisions

Today the data loader is a class. Its got a well known interface like methods like public CompletableFuture<V> load(K key) and so on AND its got a bunch of setup code.

Others have provided PRs to create new implementations. But the concrete class ness inhbits this.

I propose to make DataLoader an interface (in a breaking change) with a DataLoaderFactory for the creation of standard data loaders. (Today we have static factory methods but they should go over into a factory class)

Also today there is a caching design fault. The CacheMap says

public interface CacheMap<U, V> and it has V get(U key) but in fact its not that at all its actually needs to be CacheMap<U, CompletableFuture<V>> otherwise dataloader does not work

Many people think that the cache is a cache of values retrieved but its a cache of promises. And hence it can be serialized over the network in cache systems like REDIS etc..

I think this needs to be cleaned up a lot. I am not 100% sure how yet but its needs to be fixed.

This would also be breaking changes and hence a 3.x

Straw man interface

public interface DataLoader<K, V> {
    CompletableFuture<V> load(K key);

    Optional<CompletableFuture<V>> getIfPresent(K key);

    Optional<CompletableFuture<V>> getIfCompleted(K key);

    CompletableFuture<V> load(K key, Object keyContext);

    CompletableFuture<List<V>> loadMany(List<K> keys);

    CompletableFuture<List<V>> loadMany(List<K> keys, List<Object> keyContexts);

    DispatchResult<V> dispatch();

    List<V> dispatchAndJoin();
}
Clone this wiki locally