diff --git a/src/Cache.php b/src/Cache.php index 5a15930b..96bdec90 100644 --- a/src/Cache.php +++ b/src/Cache.php @@ -73,6 +73,20 @@ public static function put($contents) public static function setFilename($filename) { self::$filename = $filename; + self::makeFolderForFilename(); + } + + /** + * Try to create the folder recursively where the cache file is stored. + * It depends on current value of static::getFilename(). + */ + private static function makeFolderForFilename() + { + $filename = self::getFilename(); + $dirname = dirname($filename); + if (!file_exists($dirname)) { + mkdir($dirname, 0777, true); + } } /**