Add cache support.

* Make it more testable and add basic tests.
* Add tox for testing in 2.6 and 2.7.