Cache improvements.

- Some PEP8 fixes
- Used tempfile to create the cache in a temporary directory