Write disk cache atomically
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 8 Sep 2014 16:24:12 +0000 (18:24 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Mon, 8 Sep 2014 16:27:32 +0000 (18:27 +0200)
wcfsetup/install/files/lib/system/cache/source/DiskCacheSource.class.php

index 639d8ad43e07507b338c0a5136bc00ceb43a94be..d37cd417e9382cd6d242f69837b9a939a6583c2f 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 namespace wcf\system\cache\source;
 use wcf\system\exception\SystemException;
-use wcf\system\io\File;
+use wcf\system\io\AtomicWriter;
 use wcf\system\Callback;
 use wcf\system\Regex;
 use wcf\system\WCF;
@@ -68,10 +68,11 @@ class DiskCacheSource implements ICacheSource {
         * @see \wcf\system\cache\source\ICacheSource::set()
         */
        public function set($cacheName, $value, $maxLifetime) {
-               $file = new File($this->getFilename($cacheName));
-               $file->write("<?php exit; /* cache: ".$cacheName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n");
-               $file->write(serialize($value));
-               $file->close();
+               $writer = new AtomicWriter($this->getFilename($cacheName));
+               $writer->write("<?php exit; /* cache: ".$cacheName." (generated at ".gmdate('r').") DO NOT EDIT THIS FILE */ ?>\n");
+               $writer->write(serialize($value));
+               $writer->flush();
+               $writer->close();
                
                // unset current DirectoryUtil object to make sure new cache file
                // can be deleted in the same request