{"action":"created","comment":{"url":"https://api.github.com/repos/hashicorp/golang-lru/pulls/comments/25833679","id":25833679,"diff_hunk":"@@ -40,8 +46,13 @@ func New(size int) (*Cache, error) {\n func (c *Cache) Purge() {\n \tc.lock.Lock()\n \tdefer c.lock.Unlock()\n-\tc.evictList = list.New()\n-\tc.items = make(map[interface{}]*list.Element, c.size)\n+","path":"lru.go","position":33,"original_position":33,"commit_id":"a2bf154aaef12b7244ec8938794cbb7b21cd7880","original_commit_id":"a2bf154aaef12b7244ec8938794cbb7b21cd7880","user":{"login":"armon","id":592032,"avatar_url":"https://avatars.githubusercontent.com/u/592032?v=3","gravatar_id":"","url":"https://api.github.com/users/armon","html_url":"https://github.com/armon","followers_url":"https://api.github.com/users/armon/followers","following_url":"https://api.github.com/users/armon/following{/other_user}","gists_url":"https://api.github.com/users/armon/gists{/gist_id}","starred_url":"https://api.github.com/users/armon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/armon/subscriptions","organizations_url":"https://api.github.com/users/armon/orgs","repos_url":"https://api.github.com/users/armon/repos","events_url":"https://api.github.com/users/armon/events{/privacy}","received_events_url":"https://api.github.com/users/armon/received_events","type":"User","site_admin":false},"body":"This is still unnecessarily slow. I would just do:\r\n\r\n```\r\nif c.onEvicted != nil {\r\n  for k, v := range c.items {\r\n    c.onEvicted(k, v.value)\r\n  }\r\n}\r\nc.evictList = list.New()\r\nc.items = = make(map[interface{}]*list.Element, c.size)\r\n```","created_at":"2015-03-05T01:52:07Z","updated_at":"2015-03-05T01:52:07Z","html_url":"https://github.com/hashicorp/golang-lru/pull/4#discussion_r25833679","pull_request_url":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/hashicorp/golang-lru/pulls/comments/25833679"},"html":{"href":"https://github.com/hashicorp/golang-lru/pull/4#discussion_r25833679"},"pull_request":{"href":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4","id":30098045,"html_url":"https://github.com/hashicorp/golang-lru/pull/4","diff_url":"https://github.com/hashicorp/golang-lru/pull/4.diff","patch_url":"https://github.com/hashicorp/golang-lru/pull/4.patch","issue_url":"https://api.github.com/repos/hashicorp/golang-lru/issues/4","number":4,"state":"open","locked":false,"title":"Add an 'onEvict' function called when an element is removed.","user":{"login":"mreid-moz","id":969479,"avatar_url":"https://avatars.githubusercontent.com/u/969479?v=3","gravatar_id":"","url":"https://api.github.com/users/mreid-moz","html_url":"https://github.com/mreid-moz","followers_url":"https://api.github.com/users/mreid-moz/followers","following_url":"https://api.github.com/users/mreid-moz/following{/other_user}","gists_url":"https://api.github.com/users/mreid-moz/gists{/gist_id}","starred_url":"https://api.github.com/users/mreid-moz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mreid-moz/subscriptions","organizations_url":"https://api.github.com/users/mreid-moz/orgs","repos_url":"https://api.github.com/users/mreid-moz/repos","events_url":"https://api.github.com/users/mreid-moz/events{/privacy}","received_events_url":"https://api.github.com/users/mreid-moz/received_events","type":"User","site_admin":false},"body":"I wanted to keep an LRU cache of open files, so I need a hook for closing the files as they're evicted from the cache.\r\n\r\nA side effect is that the Purge operation is now probably slower, since we have to remove each element individually to ensure that `OnEvicted` gets called for each element. If that is important, I could check if the `OnEvicted` function is missing, and if so purge the original way.","created_at":"2015-02-26T17:28:58Z","updated_at":"2015-03-05T01:52:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14e74c64f2eae9267e6aca189a8b1dfc99fb8e55","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4/commits","review_comments_url":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4/comments","review_comment_url":"https://api.github.com/repos/hashicorp/golang-lru/pulls/comments{/number}","comments_url":"https://api.github.com/repos/hashicorp/golang-lru/issues/4/comments","statuses_url":"https://api.github.com/repos/hashicorp/golang-lru/statuses/a2bf154aaef12b7244ec8938794cbb7b21cd7880","head":{"label":"mreid-moz:add_onevict","ref":"add_onevict","sha":"a2bf154aaef12b7244ec8938794cbb7b21cd7880","user":{"login":"mreid-moz","id":969479,"avatar_url":"https://avatars.githubusercontent.com/u/969479?v=3","gravatar_id":"","url":"https://api.github.com/users/mreid-moz","html_url":"https://github.com/mreid-moz","followers_url":"https://api.github.com/users/mreid-moz/followers","following_url":"https://api.github.com/users/mreid-moz/following{/other_user}","gists_url":"https://api.github.com/users/mreid-moz/gists{/gist_id}","starred_url":"https://api.github.com/users/mreid-moz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mreid-moz/subscriptions","organizations_url":"https://api.github.com/users/mreid-moz/orgs","repos_url":"https://api.github.com/users/mreid-moz/repos","events_url":"https://api.github.com/users/mreid-moz/events{/privacy}","received_events_url":"https://api.github.com/users/mreid-moz/received_events","type":"User","site_admin":false},"repo":{"id":31377966,"name":"golang-lru","full_name":"mreid-moz/golang-lru","owner":{"login":"mreid-moz","id":969479,"avatar_url":"https://avatars.githubusercontent.com/u/969479?v=3","gravatar_id":"","url":"https://api.github.com/users/mreid-moz","html_url":"https://github.com/mreid-moz","followers_url":"https://api.github.com/users/mreid-moz/followers","following_url":"https://api.github.com/users/mreid-moz/following{/other_user}","gists_url":"https://api.github.com/users/mreid-moz/gists{/gist_id}","starred_url":"https://api.github.com/users/mreid-moz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mreid-moz/subscriptions","organizations_url":"https://api.github.com/users/mreid-moz/orgs","repos_url":"https://api.github.com/users/mreid-moz/repos","events_url":"https://api.github.com/users/mreid-moz/events{/privacy}","received_events_url":"https://api.github.com/users/mreid-moz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mreid-moz/golang-lru","description":"Golang LRU cache","fork":true,"url":"https://api.github.com/repos/mreid-moz/golang-lru","forks_url":"https://api.github.com/repos/mreid-moz/golang-lru/forks","keys_url":"https://api.github.com/repos/mreid-moz/golang-lru/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mreid-moz/golang-lru/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mreid-moz/golang-lru/teams","hooks_url":"https://api.github.com/repos/mreid-moz/golang-lru/hooks","issue_events_url":"https://api.github.com/repos/mreid-moz/golang-lru/issues/events{/number}","events_url":"https://api.github.com/repos/mreid-moz/golang-lru/events","assignees_url":"https://api.github.com/repos/mreid-moz/golang-lru/assignees{/user}","branches_url":"https://api.github.com/repos/mreid-moz/golang-lru/branches{/branch}","tags_url":"https://api.github.com/repos/mreid-moz/golang-lru/tags","blobs_url":"https://api.github.com/repos/mreid-moz/golang-lru/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mreid-moz/golang-lru/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mreid-moz/golang-lru/git/refs{/sha}","trees_url":"https://api.github.com/repos/mreid-moz/golang-lru/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mreid-moz/golang-lru/statuses/{sha}","languages_url":"https://api.github.com/repos/mreid-moz/golang-lru/languages","stargazers_url":"https://api.github.com/repos/mreid-moz/golang-lru/stargazers","contributors_url":"https://api.github.com/repos/mreid-moz/golang-lru/contributors","subscribers_url":"https://api.github.com/repos/mreid-moz/golang-lru/subscribers","subscription_url":"https://api.github.com/repos/mreid-moz/golang-lru/subscription","commits_url":"https://api.github.com/repos/mreid-moz/golang-lru/commits{/sha}","git_commits_url":"https://api.github.com/repos/mreid-moz/golang-lru/git/commits{/sha}","comments_url":"https://api.github.com/repos/mreid-moz/golang-lru/comments{/number}","issue_comment_url":"https://api.github.com/repos/mreid-moz/golang-lru/issues/comments{/number}","contents_url":"https://api.github.com/repos/mreid-moz/golang-lru/contents/{+path}","compare_url":"https://api.github.com/repos/mreid-moz/golang-lru/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mreid-moz/golang-lru/merges","archive_url":"https://api.github.com/repos/mreid-moz/golang-lru/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mreid-moz/golang-lru/downloads","issues_url":"https://api.github.com/repos/mreid-moz/golang-lru/issues{/number}","pulls_url":"https://api.github.com/repos/mreid-moz/golang-lru/pulls{/number}","milestones_url":"https://api.github.com/repos/mreid-moz/golang-lru/milestones{/number}","notifications_url":"https://api.github.com/repos/mreid-moz/golang-lru/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mreid-moz/golang-lru/labels{/name}","releases_url":"https://api.github.com/repos/mreid-moz/golang-lru/releases{/id}","created_at":"2015-02-26T17:02:19Z","updated_at":"2015-02-26T19:36:07Z","pushed_at":"2015-02-28T20:35:45Z","git_url":"git://github.com/mreid-moz/golang-lru.git","ssh_url":"git@github.com:mreid-moz/golang-lru.git","clone_url":"https://github.com/mreid-moz/golang-lru.git","svn_url":"https://github.com/mreid-moz/golang-lru","homepage":null,"size":87,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"hashicorp:master","ref":"master","sha":"f09f965649501e2ac1b0c310c632a7bebdbdc1d4","user":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"repo":{"id":22700054,"name":"golang-lru","full_name":"hashicorp/golang-lru","owner":{"login":"hashicorp","id":761456,"avatar_url":"https://avatars.githubusercontent.com/u/761456?v=3","gravatar_id":"","url":"https://api.github.com/users/hashicorp","html_url":"https://github.com/hashicorp","followers_url":"https://api.github.com/users/hashicorp/followers","following_url":"https://api.github.com/users/hashicorp/following{/other_user}","gists_url":"https://api.github.com/users/hashicorp/gists{/gist_id}","starred_url":"https://api.github.com/users/hashicorp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hashicorp/subscriptions","organizations_url":"https://api.github.com/users/hashicorp/orgs","repos_url":"https://api.github.com/users/hashicorp/repos","events_url":"https://api.github.com/users/hashicorp/events{/privacy}","received_events_url":"https://api.github.com/users/hashicorp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/hashicorp/golang-lru","description":"Golang LRU cache","fork":false,"url":"https://api.github.com/repos/hashicorp/golang-lru","forks_url":"https://api.github.com/repos/hashicorp/golang-lru/forks","keys_url":"https://api.github.com/repos/hashicorp/golang-lru/keys{/key_id}","collaborators_url":"https://api.github.com/repos/hashicorp/golang-lru/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/hashicorp/golang-lru/teams","hooks_url":"https://api.github.com/repos/hashicorp/golang-lru/hooks","issue_events_url":"https://api.github.com/repos/hashicorp/golang-lru/issues/events{/number}","events_url":"https://api.github.com/repos/hashicorp/golang-lru/events","assignees_url":"https://api.github.com/repos/hashicorp/golang-lru/assignees{/user}","branches_url":"https://api.github.com/repos/hashicorp/golang-lru/branches{/branch}","tags_url":"https://api.github.com/repos/hashicorp/golang-lru/tags","blobs_url":"https://api.github.com/repos/hashicorp/golang-lru/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/hashicorp/golang-lru/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/hashicorp/golang-lru/git/refs{/sha}","trees_url":"https://api.github.com/repos/hashicorp/golang-lru/git/trees{/sha}","statuses_url":"https://api.github.com/repos/hashicorp/golang-lru/statuses/{sha}","languages_url":"https://api.github.com/repos/hashicorp/golang-lru/languages","stargazers_url":"https://api.github.com/repos/hashicorp/golang-lru/stargazers","contributors_url":"https://api.github.com/repos/hashicorp/golang-lru/contributors","subscribers_url":"https://api.github.com/repos/hashicorp/golang-lru/subscribers","subscription_url":"https://api.github.com/repos/hashicorp/golang-lru/subscription","commits_url":"https://api.github.com/repos/hashicorp/golang-lru/commits{/sha}","git_commits_url":"https://api.github.com/repos/hashicorp/golang-lru/git/commits{/sha}","comments_url":"https://api.github.com/repos/hashicorp/golang-lru/comments{/number}","issue_comment_url":"https://api.github.com/repos/hashicorp/golang-lru/issues/comments{/number}","contents_url":"https://api.github.com/repos/hashicorp/golang-lru/contents/{+path}","compare_url":"https://api.github.com/repos/hashicorp/golang-lru/compare/{base}...{head}","merges_url":"https://api.github.com/repos/hashicorp/golang-lru/merges","archive_url":"https://api.github.com/repos/hashicorp/golang-lru/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/hashicorp/golang-lru/downloads","issues_url":"https://api.github.com/repos/hashicorp/golang-lru/issues{/number}","pulls_url":"https://api.github.com/repos/hashicorp/golang-lru/pulls{/number}","milestones_url":"https://api.github.com/repos/hashicorp/golang-lru/milestones{/number}","notifications_url":"https://api.github.com/repos/hashicorp/golang-lru/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/hashicorp/golang-lru/labels{/name}","releases_url":"https://api.github.com/repos/hashicorp/golang-lru/releases{/id}","created_at":"2014-08-06T22:14:53Z","updated_at":"2015-03-04T03:42:13Z","pushed_at":"2015-02-13T00:53:21Z","git_url":"git://github.com/hashicorp/golang-lru.git","ssh_url":"git@github.com:hashicorp/golang-lru.git","clone_url":"https://github.com/hashicorp/golang-lru.git","svn_url":"https://github.com/hashicorp/golang-lru","homepage":null,"size":182,"stargazers_count":54,"watchers_count":54,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":11,"mirror_url":null,"open_issues_count":1,"forks":11,"open_issues":1,"watchers":54,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4"},"html":{"href":"https://github.com/hashicorp/golang-lru/pull/4"},"issue":{"href":"https://api.github.com/repos/hashicorp/golang-lru/issues/4"},"comments":{"href":"https://api.github.com/repos/hashicorp/golang-lru/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/hashicorp/golang-lru/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/hashicorp/golang-lru/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/hashicorp/golang-lru/statuses/a2bf154aaef12b7244ec8938794cbb7b21cd7880"}}}}