Refactor caching using context managers.

This will remove caching responsibility from the library. Only tools are provided. It will be up to the user code to use them and cache correctly.