Added permissions and chmod when writing cache files