Refactor caching using context managers.

Provide caching facility using context managers instead of decorators.