Merge pull request #2 from qur2/master

Refactor caching using context managers.
Revert "Remove useless `repr()` call.": string substitution needs a single argument, which is why  `repr()` is useful.

This reverts commit ea52a6b02cbffa2f3363eaf792519f7c4738e0c5.