Cleanly cache the result of any function that returns a promise.