jpodwys / cache-service

A tiered caching solution for JavaScript.
MIT License
12 stars 6 forks source link

Change (some) callbacks to only trigger when complete. #23

Open JaredReisinger opened 7 years ago

JaredReisinger commented 7 years ago

This is a proof-of-concept PR for the issue raised in https://github.com/jpodwys/cache-service/issues/22. In particular, the caller-provided callback is only called when all of the cache modules have completed.

In making this change, I discovered several other issues that should probably be addressed.

JaredReisinger commented 7 years ago

Full disclosure: I'm writing a cache-service-file-system module for cache-service to have file-system-backed persistence for superagent, and also to use for a really cheap persistent data store... no dependencies on redis or memcached required, data is easily human readable and easily programmatically consumable by other tools. Also, my calling code is promise-based, so I expect for my .then() chains after a .set() to only happen after the data has been written to disk. (If I didn't have that requirement, I wouldn't put the following code in the .then(), I'd just continue immediately after calling .set().)