0.1.1 • Published 5 years ago

reason-dataloader v0.1.1

Weekly downloads
1
License
MIT
Repository
-
Last release
5 years ago

Dataloader

This is an implementation of Dataloader in Reason using Future as the async primitive.

Checkout src/dataloader.rei for the full API interface

Usage

let userLoader = Dataloader.make(userIds => getUsersByIds(userIds));

userLoader.load(1)
->Future.get(user => Js.log2("found user with ID = 1", user));

Caching

Calling the same loader instance with the same keys will result in returning cached futures;

userLoader.load(1) // Future with key = 1
userLoader.load(1) // will not issue a dispatch and returns the same Future as previous call

You can pre-populate the cache with prime(key, value), or clear the cache with clear(key) and clearAll().

It is recommended to create new instances of loaders per user request, so 1) we don't have a global cache that does not get garbage collected 2) Having multiple requests writing/reading from the same cache, resulting in unpredictable behaviors.