Refactor cache and log folder creation.