Refactor server.cache(). Closes #2126