1
Given list of employees  
List<<EMPLOYEE>EMPLOYEE> empList;

POJO class:
Employee{
int id;
String name;
String address;
}

Input: empID as key to redis cache

Redis Cache sample JSON data:

(KEY)-> (VALUE)

1 -> {name:xyz, address:USA}
2 -> {name:ABC, address:Europe}

Requirement: Iterate through employee list and for every empID fetch the employee details by making Async Cache calls.

Once all Async calls are completed. Send a list of all the employees with all their details.

CompletableFuture.supplyAsync() does the task but get() method of completableFuture waits for every Async call to complete. Thus increasing the response time.

Even allOf() and join() method are increasing the time as they wait for Async task to complete

Any suggestions to decrease the Response time from cache?

1 Answers1

0

You can add a closer (local) async cache layer before Redis to reduce number of reading ops going to Redis. In NodeJs, I'm observing 50%-100% higher throughput by doing this. Different pc setups would have different speedup. But connecting a Redis server must be always higher latency than fetching a value from RAM, right?

https://redis.io/topics/client-side-caching

Look for the tracking and broadcasting options. Even without them, you can still use an async lru cache implementation from github.

huseyin tugrul buyukisik
  • 11,469
  • 4
  • 45
  • 97