Complete memoize/cache solution for JavaScript