The batcher middleware let's you get a per request instance of a batcher object that will dedupe and batch multiple calls to the same function.
This is specially useful to avoid making multiple API calls to the same endpoint in a single request, or DB queries. The batcher will call the function only once and return the same result to all calls.
If you move your batcher.batch call to a separate function, you can use it in different route loaders and actions, and the batcher will still dedupe the calls.
The batcher middleware let's you get a per request instance of a batcher object that will dedupe and batch multiple calls to the same function.
This is specially useful to avoid making multiple API calls to the same endpoint in a single request, or DB queries. The batcher will call the function only once and return the same result to all calls.
To use it, you need to add it to the
unstable_middleware
array in the route where you want to use it.And you can use the
getBatcher
function in your loaders to get the batcher object.If you move your
batcher.batch
call to a separate function, you can use it in different route loaders and actions, and the batcher will still dedupe the calls.Then you can call it in any route loader who has access to the batcher.
Author
Sergio XalambrÃ