Have we looked at external libraries for this sort of things? Have you search for `python memoize`?