Factor out cache file generation