Skip to content

Commit

Permalink
Merge pull request #135 from CMCDragonkai/patch-1
Browse files Browse the repository at this point in the history
Opcache is a problem with the FileSystem driver
  • Loading branch information
tedivm committed Mar 30, 2014
2 parents 1c71986 + 5ddea80 commit 4a99597
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/Stash/Driver/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected static function getDataFromFile($path)
if (!file_exists($path)) {
return false;
}

include($path);

// If the item does not exist we should return false. However, it's
Expand Down Expand Up @@ -217,8 +217,19 @@ public function storeData($key, $data, $expiration)
$storeString .= '/* Type: ' . gettype($data) . ' */' . PHP_EOL;
$storeString .= "\$data = {$dataString};" . PHP_EOL;
}

$result = file_put_contents($path, $storeString, LOCK_EX);

// If opcache is switched on, it will try to cache the PHP data file
// The new php opcode caching system only revalidates against the source files once every few seconds,
// so some changes will not be caught.
// This fix immediately invalidates that opcode cache after a file is written,
// so that future includes are not using the stale opcode cached file.
if (function_exists('opcache_invalidate')) {
opcache_invalidate($path, true);
}

return false !== file_put_contents($path, $storeString, LOCK_EX);
return false !== $result;
}

protected function encode($data)
Expand Down

0 comments on commit 4a99597

Please sign in to comment.