Skip to content

Commit ef5965c

Browse files
committed
Merge pull request #115 from michaelmoussa/atomic-cache-file-writing
Achieve atomic cache writes
2 parents 0deac55 + 9fc5cab commit ef5965c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/AssetManager/Cache/FilePathCache.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public function set($key, $value)
8787
throw new \RuntimeException('Unable to write file ' . $this->cachedFile());
8888
}
8989

90-
file_put_contents($this->cachedFile(), $value);
90+
// Use "rename" to achieve atomic writes
91+
$tmpFilePath = $cacheDir . '/' . uniqid('AssetManagerFilePathCache');
92+
file_put_contents($tmpFilePath, $value);
93+
rename($tmpFilePath, $this->cachedFile());
9194
}
9295

9396
/**

0 commit comments

Comments
 (0)