Add caching of ASTs

This should hopefully improve performance quite a bit.  I'm hoping that
this will allow us to perform the refactorings synchronously rather than
asynchronously.