create directories before writing cache file