This first commit is very rough, just adding the caching as simply as possible. Refactoring is needed.