Put code to generate cache file into separate function.