Skip to content

Commit

Permalink
Cache: Optimized Filesystem::setItem with locking enabled by writing …
Browse files Browse the repository at this point in the history
…the file in non-blocking mode than delete a related tag file and after this retry writing file in blocking mode if it was blocked before
  • Loading branch information
marc-mabe committed Dec 13, 2012
1 parent 09bac30 commit 4b65908
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions library/Zend/Cache/Storage/Adapter/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,18 @@ protected function internalSetItem(& $normalizedKey, & $value)
$filespec = $this->getFileSpec($normalizedKey);
$this->prepareDirectoryStructure($filespec);

$this->putFileContent($filespec . '.dat', $value);
// write data in non-blocking mode
$wouldblock = null;
$this->putFileContent($filespec . '.dat', $value, true, $wouldblock);

// delete related tag file (if present)
$this->unlink($filespec . '.tag');

// Retry writing data in blocking mode if it was blocked before
if ($wouldblock) {
$this->putFileContent($filespec . '.dat', $value);
}

return true;
}

Expand Down Expand Up @@ -1528,7 +1537,7 @@ protected function putFileContent($file, $data, $nonBlocking = false, & $wouldbl
}
}

if (!fwrite($fp, $data)) {
if (fwrite($fp, $data) === false) {
flock($fp, \LOCK_UN);
fclose($fp);
$err = ErrorHandler::stop();
Expand Down

0 comments on commit 4b65908

Please sign in to comment.