Be more robust when loading the cache file.

This should avoid embarassing segfaults when the file is corrupted.

This probably fixes #505
Run the tests with changing the global config.
Use List.rev_map instead of List.map when needed.