Check for a directory before caching to it and create it if necessary.