factor cache_file out