Argument cache

This is a rebase of an old branch of Giovanni's. I've updated it to work with the current codebase and fixed some bugs in it (our tests have gotten more comprehensive in the last 7 years and I'm glad to see they actually do catch regressions and memory leaks!)