I'm trying to implement a cache system for a data-delivery tool for different clients with node.js. It's an http-service and I use express to handle the requests. My cache-system needs to support three cases:
Case 1 - There is no cache: The program receives the data via the given get-method. If successful it writes the cache.
Case 2 - There is a cache: The program receives the cache.
Case 3 - There is no cache but the get-method for the same request was already called by a different client and is currently being processed. The programm needs to wait until the other request received its data via the get-method and deliver the newly written cache.
I solved the problem of "Case 3" with events. I register an event for every client / request combination. But it feels not very elegant to register an open amount of events. Also the use of queues is not one of the best solutions.