Skip to content

Commit 132e704

Browse files
staabmclxmstaab
andauthored
try to create cache file if none exist (#159)
Co-authored-by: Markus Staab <[email protected]>
1 parent 0be1424 commit 132e704

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/QueryReflection/ReflectionCache.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ public static function create(string $cacheFile): self
4040

4141
public static function load(string $cacheFile): self
4242
{
43-
if (!is_readable($cacheFile)) {
44-
throw new DbaException(sprintf('Cache file "%s" is not readable', $cacheFile));
45-
}
46-
4743
$reflectionCache = new self($cacheFile);
4844
$cachedRecords = $reflectionCache->readCache();
4945
if (null !== $cachedRecords) {
@@ -58,6 +54,11 @@ public static function load(string $cacheFile): self
5854
*/
5955
private function readCache(): ?array
6056
{
57+
if (!is_file($this->cacheFile)) {
58+
if (false === file_put_contents($this->cacheFile, '')) {
59+
throw new DbaException(sprintf('Cache file "%s" is not readable and creating a new one did not succeed.', $this->cacheFile));
60+
}
61+
}
6162
clearstatcache(true, $this->cacheFile);
6263
$cache = require $this->cacheFile;
6364

0 commit comments

Comments
 (0)