Improved handling of cache directories

Improves:
1) handling of cache directory with multiple levels ( test/cache/1/ )
2) handling of directory name without trailing /
   Before cache files would not be stored in the directory as expected.

By using path.Join(), directory paths are also cleaned.