diff --git a/src/Cache/FileCacheStorage.php b/src/Cache/FileCacheStorage.php index 9b10d7ebc5..cdf660b43c 100644 --- a/src/Cache/FileCacheStorage.php +++ b/src/Cache/FileCacheStorage.php @@ -56,6 +56,9 @@ public function load(string $key, string $variableKey) */ public function save(string $key, string $variableKey, $data): void { + $path = $this->getFilePath($key); + $this->makeDir(dirname($path)); + $tmpPath = sprintf('%s/%s.tmp', $this->directory, Random::generate()); $tmpSuccess = @file_put_contents( $tmpPath, @@ -68,8 +71,6 @@ public function save(string $key, string $variableKey, $data): void throw new \InvalidArgumentException(sprintf('Could not write data to cache file %s.', $tmpPath)); } - $path = $this->getFilePath($key); - $this->makeDir(dirname($path)); @rename($tmpPath, $path); }