Fix bug with cache's parent directory not existing (#4988)

By changing the function used to create the cache from ``os.mkdir``
to ``os.makedirs`` we now handle non-existing parent directories
correctly.
This closes #4900
3 files changed