{"action":"created","issue":{"url":"https://api.github.com/repos/alastairtree/LazyCache/issues/48","repository_url":"https://api.github.com/repos/alastairtree/LazyCache","labels_url":"https://api.github.com/repos/alastairtree/LazyCache/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/alastairtree/LazyCache/issues/48/comments","events_url":"https://api.github.com/repos/alastairtree/LazyCache/issues/48/events","html_url":"https://github.com/alastairtree/LazyCache/issues/48","id":342327927,"node_id":"MDU6SXNzdWUzNDIzMjc5Mjc=","number":48,"title":"Double check lock in GetOrAdd","user":{"login":"MaximTkachenko","id":1560515,"node_id":"MDQ6VXNlcjE1NjA1MTU=","avatar_url":"https://avatars3.githubusercontent.com/u/1560515?v=4","gravatar_id":"","url":"https://api.github.com/users/MaximTkachenko","html_url":"https://github.com/MaximTkachenko","followers_url":"https://api.github.com/users/MaximTkachenko/followers","following_url":"https://api.github.com/users/MaximTkachenko/following{/other_user}","gists_url":"https://api.github.com/users/MaximTkachenko/gists{/gist_id}","starred_url":"https://api.github.com/users/MaximTkachenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaximTkachenko/subscriptions","organizations_url":"https://api.github.com/users/MaximTkachenko/orgs","repos_url":"https://api.github.com/users/MaximTkachenko/repos","events_url":"https://api.github.com/users/MaximTkachenko/events{/privacy}","received_events_url":"https://api.github.com/users/MaximTkachenko/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-07-18T13:26:40Z","updated_at":"2018-07-20T13:54:05Z","closed_at":null,"author_association":"NONE","body":"What do you thin about using double check lock approach in `CachingService.GetOrAdd` like this: `1.` try get value from cache `2.` if key is missed aquire lock `3.` get or create inside lock?"},"comment":{"url":"https://api.github.com/repos/alastairtree/LazyCache/issues/comments/406607462","html_url":"https://github.com/alastairtree/LazyCache/issues/48#issuecomment-406607462","issue_url":"https://api.github.com/repos/alastairtree/LazyCache/issues/48","id":406607462,"node_id":"MDEyOklzc3VlQ29tbWVudDQwNjYwNzQ2Mg==","user":{"login":"alastairtree","id":6273429,"node_id":"MDQ6VXNlcjYyNzM0Mjk=","avatar_url":"https://avatars2.githubusercontent.com/u/6273429?v=4","gravatar_id":"","url":"https://api.github.com/users/alastairtree","html_url":"https://github.com/alastairtree","followers_url":"https://api.github.com/users/alastairtree/followers","following_url":"https://api.github.com/users/alastairtree/following{/other_user}","gists_url":"https://api.github.com/users/alastairtree/gists{/gist_id}","starred_url":"https://api.github.com/users/alastairtree/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alastairtree/subscriptions","organizations_url":"https://api.github.com/users/alastairtree/orgs","repos_url":"https://api.github.com/users/alastairtree/repos","events_url":"https://api.github.com/users/alastairtree/events{/privacy}","received_events_url":"https://api.github.com/users/alastairtree/received_events","type":"User","site_admin":false},"created_at":"2018-07-20T13:54:05Z","updated_at":"2018-07-20T13:54:05Z","author_association":"OWNER","body":"Yes that strategy may work but what you describe is not quite double check locking in the traditional sense.  It would depend if the 1 Get and 1 occasional GetOrAdd call combination were more performant than the blanket locking approach used currently. also would need some thorough testing, and need to be aware of the locking across both sync and async versions of the method.\r\n\r\nTBH I just followed the Jon Skeek advise below for ease!\r\n\r\n> Personally, if I'm in a situation where I have to choose between double-checked locking and \"lock every time\" code I'd go for locking every time until I'd got real evidence that it was causing a bottleneck. When it comes to threading, a simple and obviously-correct pattern is worth a lot.\r\n\r\nhttps://stackoverflow.com/a/394932/3140853"}}
{"actor":{"display_login":"alastairtree"}}