Custom cache managers

This pull request allows one to create and use custom cache managers.

Also, it enables actual caching of documents again... :/