{"action":"created","comment":{"url":"https://api.github.com/repos/nette/latte/pulls/comments/23138591","id":23138591,"diff_hunk":"@@ -156,33 +156,53 @@ private function loadCacheFile($name, $params)\n \t\t}\n \n \t\t$file = $this->getCacheFile($name);\n-\t\t$handle = fopen($file, 'c+');\n+\t\tif ($this->autoRefresh && $this->getLoader()->isExpired($name, (int) @filemtime($file))) {\n+\t\t\t@unlink($file);\n+\n+\t\t} elseif (self::tryInclude($file, $params)) {\n+\t\t\treturn;\n+\t\t}\n+\n+\t\tif (!is_dir($this->tempDirectory)) {\n+\t\t\t@mkdir($this->tempDirectory);\n+\t\t}\n+\n+\t\t$handle = fopen(\"$file.lock\", 'c+');\n \t\tif (!$handle) {\n-\t\t\tthrow new \\RuntimeException(\"Unable to open or create file '$file'.\");\n+\t\t\tthrow new \\RuntimeException(\"Unable to open or create file '$file.lock'.\");\n \t\t}\n-\t\tflock($handle, LOCK_SH);\n-\t\t$stat = fstat($handle);\n-\t\tif (!$stat['size'] || ($this->autoRefresh && $this->getLoader()->isExpired($name, $stat['mtime']))) {\n-\t\t\tftruncate($handle, 0);\n-\t\t\tflock($handle, LOCK_EX);\n-\t\t\t$stat = fstat($handle);\n-\t\t\tif (!$stat['size']) {\n-\t\t\t\t$code = $this->compile($name);\n-\t\t\t\tif (fwrite($handle, $code, strlen($code)) !== strlen($code)) {\n-\t\t\t\t\tftruncate($handle, 0);\n-\t\t\t\t\tthrow new \\RuntimeException(\"Unable to write file '$file'.\");\n-\t\t\t\t}\n+\n+\t\tif (flock($handle, LOCK_EX) && !is_file($file)) {\n+\t\t\t$code = $this->compile($name);","path":"src/Latte/Engine.php","position":35,"original_position":35,"commit_id":"640687b2b3fcda2d5343efb48799dc8551336ead","original_commit_id":"640687b2b3fcda2d5343efb48799dc8551336ead","user":{"login":"JanTvrdik","id":175109,"avatar_url":"https://avatars.githubusercontent.com/u/175109?v=3","gravatar_id":"","url":"https://api.github.com/users/JanTvrdik","html_url":"https://github.com/JanTvrdik","followers_url":"https://api.github.com/users/JanTvrdik/followers","following_url":"https://api.github.com/users/JanTvrdik/following{/other_user}","gists_url":"https://api.github.com/users/JanTvrdik/gists{/gist_id}","starred_url":"https://api.github.com/users/JanTvrdik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanTvrdik/subscriptions","organizations_url":"https://api.github.com/users/JanTvrdik/orgs","repos_url":"https://api.github.com/users/JanTvrdik/repos","events_url":"https://api.github.com/users/JanTvrdik/events{/privacy}","received_events_url":"https://api.github.com/users/JanTvrdik/received_events","type":"User","site_admin":false},"body":"`flock` may fail. We should not compile the template if we don't have the lock.","created_at":"2015-01-19T00:09:37Z","updated_at":"2015-01-19T00:09:37Z","html_url":"https://github.com/nette/latte/pull/49#discussion_r23138591","pull_request_url":"https://api.github.com/repos/nette/latte/pulls/49","_links":{"self":{"href":"https://api.github.com/repos/nette/latte/pulls/comments/23138591"},"html":{"href":"https://github.com/nette/latte/pull/49#discussion_r23138591"},"pull_request":{"href":"https://api.github.com/repos/nette/latte/pulls/49"}}},"pull_request":{"url":"https://api.github.com/repos/nette/latte/pulls/49","id":27574715,"html_url":"https://github.com/nette/latte/pull/49","diff_url":"https://github.com/nette/latte/pull/49.diff","patch_url":"https://github.com/nette/latte/pull/49.patch","issue_url":"https://api.github.com/repos/nette/latte/issues/49","number":49,"state":"open","locked":false,"title":"Engine: optimized loadCacheFile() performance","user":{"login":"JanTvrdik","id":175109,"avatar_url":"https://avatars.githubusercontent.com/u/175109?v=3","gravatar_id":"","url":"https://api.github.com/users/JanTvrdik","html_url":"https://github.com/JanTvrdik","followers_url":"https://api.github.com/users/JanTvrdik/followers","following_url":"https://api.github.com/users/JanTvrdik/following{/other_user}","gists_url":"https://api.github.com/users/JanTvrdik/gists{/gist_id}","starred_url":"https://api.github.com/users/JanTvrdik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanTvrdik/subscriptions","organizations_url":"https://api.github.com/users/JanTvrdik/orgs","repos_url":"https://api.github.com/users/JanTvrdik/repos","events_url":"https://api.github.com/users/JanTvrdik/events{/privacy}","received_events_url":"https://api.github.com/users/JanTvrdik/received_events","type":"User","site_admin":false},"body":"It's mostly similar to what `DI\\ContainerLoader` does. Shouldn't we write the code to temporary file first and them use `rename`?\r\n\r\n---\r\n\r\nEdit: I've tried slightly different approach. Will it work?","created_at":"2015-01-18T18:23:08Z","updated_at":"2015-01-19T00:09:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"879fab39076a5b4b3029d3011fc6ec3e42a3a5dd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/nette/latte/pulls/49/commits","review_comments_url":"https://api.github.com/repos/nette/latte/pulls/49/comments","review_comment_url":"https://api.github.com/repos/nette/latte/pulls/comments/{number}","comments_url":"https://api.github.com/repos/nette/latte/issues/49/comments","statuses_url":"https://api.github.com/repos/nette/latte/statuses/640687b2b3fcda2d5343efb48799dc8551336ead","head":{"label":"JanTvrdik:load_cache_file_performance","ref":"load_cache_file_performance","sha":"640687b2b3fcda2d5343efb48799dc8551336ead","user":{"login":"JanTvrdik","id":175109,"avatar_url":"https://avatars.githubusercontent.com/u/175109?v=3","gravatar_id":"","url":"https://api.github.com/users/JanTvrdik","html_url":"https://github.com/JanTvrdik","followers_url":"https://api.github.com/users/JanTvrdik/followers","following_url":"https://api.github.com/users/JanTvrdik/following{/other_user}","gists_url":"https://api.github.com/users/JanTvrdik/gists{/gist_id}","starred_url":"https://api.github.com/users/JanTvrdik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanTvrdik/subscriptions","organizations_url":"https://api.github.com/users/JanTvrdik/orgs","repos_url":"https://api.github.com/users/JanTvrdik/repos","events_url":"https://api.github.com/users/JanTvrdik/events{/privacy}","received_events_url":"https://api.github.com/users/JanTvrdik/received_events","type":"User","site_admin":false},"repo":{"id":23041968,"name":"nette-latte","full_name":"JanTvrdik/nette-latte","owner":{"login":"JanTvrdik","id":175109,"avatar_url":"https://avatars.githubusercontent.com/u/175109?v=3","gravatar_id":"","url":"https://api.github.com/users/JanTvrdik","html_url":"https://github.com/JanTvrdik","followers_url":"https://api.github.com/users/JanTvrdik/followers","following_url":"https://api.github.com/users/JanTvrdik/following{/other_user}","gists_url":"https://api.github.com/users/JanTvrdik/gists{/gist_id}","starred_url":"https://api.github.com/users/JanTvrdik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanTvrdik/subscriptions","organizations_url":"https://api.github.com/users/JanTvrdik/orgs","repos_url":"https://api.github.com/users/JanTvrdik/repos","events_url":"https://api.github.com/users/JanTvrdik/events{/privacy}","received_events_url":"https://api.github.com/users/JanTvrdik/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JanTvrdik/nette-latte","description":"Latte: amazing template engine for PHP","fork":true,"url":"https://api.github.com/repos/JanTvrdik/nette-latte","forks_url":"https://api.github.com/repos/JanTvrdik/nette-latte/forks","keys_url":"https://api.github.com/repos/JanTvrdik/nette-latte/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JanTvrdik/nette-latte/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JanTvrdik/nette-latte/teams","hooks_url":"https://api.github.com/repos/JanTvrdik/nette-latte/hooks","issue_events_url":"https://api.github.com/repos/JanTvrdik/nette-latte/issues/events{/number}","events_url":"https://api.github.com/repos/JanTvrdik/nette-latte/events","assignees_url":"https://api.github.com/repos/JanTvrdik/nette-latte/assignees{/user}","branches_url":"https://api.github.com/repos/JanTvrdik/nette-latte/branches{/branch}","tags_url":"https://api.github.com/repos/JanTvrdik/nette-latte/tags","blobs_url":"https://api.github.com/repos/JanTvrdik/nette-latte/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JanTvrdik/nette-latte/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JanTvrdik/nette-latte/git/refs{/sha}","trees_url":"https://api.github.com/repos/JanTvrdik/nette-latte/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JanTvrdik/nette-latte/statuses/{sha}","languages_url":"https://api.github.com/repos/JanTvrdik/nette-latte/languages","stargazers_url":"https://api.github.com/repos/JanTvrdik/nette-latte/stargazers","contributors_url":"https://api.github.com/repos/JanTvrdik/nette-latte/contributors","subscribers_url":"https://api.github.com/repos/JanTvrdik/nette-latte/subscribers","subscription_url":"https://api.github.com/repos/JanTvrdik/nette-latte/subscription","commits_url":"https://api.github.com/repos/JanTvrdik/nette-latte/commits{/sha}","git_commits_url":"https://api.github.com/repos/JanTvrdik/nette-latte/git/commits{/sha}","comments_url":"https://api.github.com/repos/JanTvrdik/nette-latte/comments{/number}","issue_comment_url":"https://api.github.com/repos/JanTvrdik/nette-latte/issues/comments/{number}","contents_url":"https://api.github.com/repos/JanTvrdik/nette-latte/contents/{+path}","compare_url":"https://api.github.com/repos/JanTvrdik/nette-latte/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JanTvrdik/nette-latte/merges","archive_url":"https://api.github.com/repos/JanTvrdik/nette-latte/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JanTvrdik/nette-latte/downloads","issues_url":"https://api.github.com/repos/JanTvrdik/nette-latte/issues{/number}","pulls_url":"https://api.github.com/repos/JanTvrdik/nette-latte/pulls{/number}","milestones_url":"https://api.github.com/repos/JanTvrdik/nette-latte/milestones{/number}","notifications_url":"https://api.github.com/repos/JanTvrdik/nette-latte/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JanTvrdik/nette-latte/labels{/name}","releases_url":"https://api.github.com/repos/JanTvrdik/nette-latte/releases{/id}","created_at":"2014-08-17T14:13:17Z","updated_at":"2015-01-18T18:20:59Z","pushed_at":"2015-01-18T22:08:26Z","git_url":"git://github.com/JanTvrdik/nette-latte.git","ssh_url":"git@github.com:JanTvrdik/nette-latte.git","clone_url":"https://github.com/JanTvrdik/nette-latte.git","svn_url":"https://github.com/JanTvrdik/nette-latte","homepage":"http://latte.nette.org","size":1251,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"nette:master","ref":"master","sha":"6d4a81b5113052c79c8e1518c8a8c1f156631422","user":{"login":"nette","id":99965,"avatar_url":"https://avatars.githubusercontent.com/u/99965?v=3","gravatar_id":"","url":"https://api.github.com/users/nette","html_url":"https://github.com/nette","followers_url":"https://api.github.com/users/nette/followers","following_url":"https://api.github.com/users/nette/following{/other_user}","gists_url":"https://api.github.com/users/nette/gists{/gist_id}","starred_url":"https://api.github.com/users/nette/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nette/subscriptions","organizations_url":"https://api.github.com/users/nette/orgs","repos_url":"https://api.github.com/users/nette/repos","events_url":"https://api.github.com/users/nette/events{/privacy}","received_events_url":"https://api.github.com/users/nette/received_events","type":"Organization","site_admin":false},"repo":{"id":4732503,"name":"latte","full_name":"nette/latte","owner":{"login":"nette","id":99965,"avatar_url":"https://avatars.githubusercontent.com/u/99965?v=3","gravatar_id":"","url":"https://api.github.com/users/nette","html_url":"https://github.com/nette","followers_url":"https://api.github.com/users/nette/followers","following_url":"https://api.github.com/users/nette/following{/other_user}","gists_url":"https://api.github.com/users/nette/gists{/gist_id}","starred_url":"https://api.github.com/users/nette/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nette/subscriptions","organizations_url":"https://api.github.com/users/nette/orgs","repos_url":"https://api.github.com/users/nette/repos","events_url":"https://api.github.com/users/nette/events{/privacy}","received_events_url":"https://api.github.com/users/nette/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/nette/latte","description":"Latte: amazing template engine for PHP","fork":false,"url":"https://api.github.com/repos/nette/latte","forks_url":"https://api.github.com/repos/nette/latte/forks","keys_url":"https://api.github.com/repos/nette/latte/keys{/key_id}","collaborators_url":"https://api.github.com/repos/nette/latte/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/nette/latte/teams","hooks_url":"https://api.github.com/repos/nette/latte/hooks","issue_events_url":"https://api.github.com/repos/nette/latte/issues/events{/number}","events_url":"https://api.github.com/repos/nette/latte/events","assignees_url":"https://api.github.com/repos/nette/latte/assignees{/user}","branches_url":"https://api.github.com/repos/nette/latte/branches{/branch}","tags_url":"https://api.github.com/repos/nette/latte/tags","blobs_url":"https://api.github.com/repos/nette/latte/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/nette/latte/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/nette/latte/git/refs{/sha}","trees_url":"https://api.github.com/repos/nette/latte/git/trees{/sha}","statuses_url":"https://api.github.com/repos/nette/latte/statuses/{sha}","languages_url":"https://api.github.com/repos/nette/latte/languages","stargazers_url":"https://api.github.com/repos/nette/latte/stargazers","contributors_url":"https://api.github.com/repos/nette/latte/contributors","subscribers_url":"https://api.github.com/repos/nette/latte/subscribers","subscription_url":"https://api.github.com/repos/nette/latte/subscription","commits_url":"https://api.github.com/repos/nette/latte/commits{/sha}","git_commits_url":"https://api.github.com/repos/nette/latte/git/commits{/sha}","comments_url":"https://api.github.com/repos/nette/latte/comments{/number}","issue_comment_url":"https://api.github.com/repos/nette/latte/issues/comments/{number}","contents_url":"https://api.github.com/repos/nette/latte/contents/{+path}","compare_url":"https://api.github.com/repos/nette/latte/compare/{base}...{head}","merges_url":"https://api.github.com/repos/nette/latte/merges","archive_url":"https://api.github.com/repos/nette/latte/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/nette/latte/downloads","issues_url":"https://api.github.com/repos/nette/latte/issues{/number}","pulls_url":"https://api.github.com/repos/nette/latte/pulls{/number}","milestones_url":"https://api.github.com/repos/nette/latte/milestones{/number}","notifications_url":"https://api.github.com/repos/nette/latte/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/nette/latte/labels{/name}","releases_url":"https://api.github.com/repos/nette/latte/releases{/id}","created_at":"2012-06-20T22:59:09Z","updated_at":"2015-01-12T10:33:24Z","pushed_at":"2015-01-12T19:04:00Z","git_url":"git://github.com/nette/latte.git","ssh_url":"git@github.com:nette/latte.git","clone_url":"https://github.com/nette/latte.git","svn_url":"https://github.com/nette/latte","homepage":"http://latte.nette.org","size":2863,"stargazers_count":135,"watchers_count":135,"language":"PHP","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":16,"mirror_url":null,"open_issues_count":12,"forks":16,"open_issues":12,"watchers":135,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/nette/latte/pulls/49"},"html":{"href":"https://github.com/nette/latte/pull/49"},"issue":{"href":"https://api.github.com/repos/nette/latte/issues/49"},"comments":{"href":"https://api.github.com/repos/nette/latte/issues/49/comments"},"review_comments":{"href":"https://api.github.com/repos/nette/latte/pulls/49/comments"},"review_comment":{"href":"https://api.github.com/repos/nette/latte/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/nette/latte/pulls/49/commits"},"statuses":{"href":"https://api.github.com/repos/nette/latte/statuses/640687b2b3fcda2d5343efb48799dc8551336ead"}}}}