reason-dataloader

0.1.1 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i reason-dataloader

Weekly Downloads

0

Version

0.1.1

License

MIT

Unpacked Size

176 kB

Total Files

10

Last publish

Collaborators

  • sikanx