Looking at the caller of this code, I think the already-cached case is the common code path.  So we probably want to put this check and makedirs() into the else: clause below.