Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opcache is a problem with the FileSystem driver #135

Merged
merged 4 commits into from
Mar 30, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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