{"action":"created","comment":{"url":"https://api.github.com/repos/twosigma/Cook/pulls/comments/238391474","pull_request_review_id":180921261,"id":238391474,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzODM5MTQ3NA==","diff_hunk":"@@ -0,0 +1,52 @@\n+(ns cook.cache\n+  (:require [clj-time.core :as t])\n+  (:import (com.google.common.cache Cache)))\n+\n+\n+(defn lookup-cache!\n+  \"Generic cache. Caches under a key (extracted from the item with extract-key-fn. Uses miss-fn to fill\n+  any misses. Caches only positive hits where both functions return non-nil\"\n+  [^Cache cache extract-key-fn miss-fn item]\n+  (if-let [key (extract-key-fn item)]\n+    (if-let [result (.getIfPresent cache key)]\n+      result ; we got a hit.\n+      (let [new-result (miss-fn item)]\n+        ; Only cache non-nil\n+        (when new-result\n+          (.put cache key new-result))\n+        new-result))\n+    (miss-fn item)))\n+\n+(defn expire-key!\n+  \"Generic cache. Caches under a key (extracted from the item with extract-key-fn. Uses miss-fn to fill\n+  any misses. Caches only positive hits where both functions return non-nil. Also handles expiration if the value\n+  is a map with the key :cache-expires-at.\"\n+  [^Cache cache extract-key-fn item]\n+  (if-let [key (extract-key-fn item)]\n+    (locking cache ; TOOD: Consider lock striping based on hashcode of the key to allow concurrent loads.\n+      ; If it has a timed expiration, expire it.\n+      (when-let [result (.getIfPresent cache key)]\n+        (let [{:keys [cache-expires-at]} result]\n+          (when (and cache-expires-at (t/after? (t/now) cache-expires-at))  (.invalidate cache key)))))))\n+\n+\n+(defn lookup-cache-with-expiration!\n+  \"Generic cache. Caches under a key (extracted from the item with extract-key-fn. Uses miss-fn to fill\n+  any misses. Caches only positive hits where both functions return non-nil. Also handles expiration if the value\n+  is a map with the key :cache-expires-at.\"\n+  [^Cache cache extract-key-fn miss-fn item]\n+  (if-let [key (extract-key-fn item)]\n+    (locking cache ; TOOD: Consider lock striping based on hashcode of the key to allow concurrent loads.\n+      ; If it has a timed expiration, expire it.\n+      (when-let [result (.getIfPresent cache key)]","path":"scheduler/src/cook/cache.clj","position":41,"original_position":41,"commit_id":"c3d0b4b603b05c1cd6b32ed7834d3d0f23c1fe88","original_commit_id":"c3d0b4b603b05c1cd6b32ed7834d3d0f23c1fe88","user":{"login":"pschorf","id":88803,"node_id":"MDQ6VXNlcjg4ODAz","avatar_url":"https://avatars0.githubusercontent.com/u/88803?v=4","gravatar_id":"","url":"https://api.github.com/users/pschorf","html_url":"https://github.com/pschorf","followers_url":"https://api.github.com/users/pschorf/followers","following_url":"https://api.github.com/users/pschorf/following{/other_user}","gists_url":"https://api.github.com/users/pschorf/gists{/gist_id}","starred_url":"https://api.github.com/users/pschorf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pschorf/subscriptions","organizations_url":"https://api.github.com/users/pschorf/orgs","repos_url":"https://api.github.com/users/pschorf/repos","events_url":"https://api.github.com/users/pschorf/events{/privacy}","received_events_url":"https://api.github.com/users/pschorf/received_events","type":"User","site_admin":false},"body":"Can this just be a call to `expire-key!`?","created_at":"2018-12-03T18:49:16Z","updated_at":"2018-12-03T18:49:53Z","html_url":"https://github.com/twosigma/Cook/pull/1044#discussion_r238391474","pull_request_url":"https://api.github.com/repos/twosigma/Cook/pulls/1044","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/comments/238391474"},"html":{"href":"https://github.com/twosigma/Cook/pull/1044#discussion_r238391474"},"pull_request":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/1044"}}},"pull_request":{"url":"https://api.github.com/repos/twosigma/Cook/pulls/1044","id":235523120,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM1NTIzMTIw","html_url":"https://github.com/twosigma/Cook/pull/1044","diff_url":"https://github.com/twosigma/Cook/pull/1044.diff","patch_url":"https://github.com/twosigma/Cook/pull/1044.patch","issue_url":"https://api.github.com/repos/twosigma/Cook/issues/1044","number":1044,"state":"open","locked":false,"title":"Cache refactor and add explicit expiration.","user":{"login":"scrosby","id":253292,"node_id":"MDQ6VXNlcjI1MzI5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/253292?v=4","gravatar_id":"","url":"https://api.github.com/users/scrosby","html_url":"https://github.com/scrosby","followers_url":"https://api.github.com/users/scrosby/followers","following_url":"https://api.github.com/users/scrosby/following{/other_user}","gists_url":"https://api.github.com/users/scrosby/gists{/gist_id}","starred_url":"https://api.github.com/users/scrosby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrosby/subscriptions","organizations_url":"https://api.github.com/users/scrosby/orgs","repos_url":"https://api.github.com/users/scrosby/repos","events_url":"https://api.github.com/users/scrosby/events{/privacy}","received_events_url":"https://api.github.com/users/scrosby/received_events","type":"User","site_admin":false},"body":"## Changes proposed in this PR\r\n\r\n- Refactor the guava cache code into its own toplevel namespace\r\n- Add an explicit :cache-expires-at value to the value dictionary for explicit expiration semantics\r\n- \r\n\r\n## Why are we making these changes?\r\n- This refactor makes sense.\r\n- The new :cache-expires-at will be used in the future plugin PR. \r\n\r\n","created_at":"2018-12-03T17:06:48Z","updated_at":"2018-12-03T18:49:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14a5a7c524db892d8b4f8dc9dfeb039a9256ec05","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/twosigma/Cook/pulls/1044/commits","review_comments_url":"https://api.github.com/repos/twosigma/Cook/pulls/1044/comments","review_comment_url":"https://api.github.com/repos/twosigma/Cook/pulls/comments{/number}","comments_url":"https://api.github.com/repos/twosigma/Cook/issues/1044/comments","statuses_url":"https://api.github.com/repos/twosigma/Cook/statuses/c3d0b4b603b05c1cd6b32ed7834d3d0f23c1fe88","head":{"label":"scrosby:outgoing/cook-cache","ref":"outgoing/cook-cache","sha":"c3d0b4b603b05c1cd6b32ed7834d3d0f23c1fe88","user":{"login":"scrosby","id":253292,"node_id":"MDQ6VXNlcjI1MzI5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/253292?v=4","gravatar_id":"","url":"https://api.github.com/users/scrosby","html_url":"https://github.com/scrosby","followers_url":"https://api.github.com/users/scrosby/followers","following_url":"https://api.github.com/users/scrosby/following{/other_user}","gists_url":"https://api.github.com/users/scrosby/gists{/gist_id}","starred_url":"https://api.github.com/users/scrosby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrosby/subscriptions","organizations_url":"https://api.github.com/users/scrosby/orgs","repos_url":"https://api.github.com/users/scrosby/repos","events_url":"https://api.github.com/users/scrosby/events{/privacy}","received_events_url":"https://api.github.com/users/scrosby/received_events","type":"User","site_admin":false},"repo":{"id":121643897,"node_id":"MDEwOlJlcG9zaXRvcnkxMjE2NDM4OTc=","name":"Cook","full_name":"scrosby/Cook","private":false,"owner":{"login":"scrosby","id":253292,"node_id":"MDQ6VXNlcjI1MzI5Mg==","avatar_url":"https://avatars3.githubusercontent.com/u/253292?v=4","gravatar_id":"","url":"https://api.github.com/users/scrosby","html_url":"https://github.com/scrosby","followers_url":"https://api.github.com/users/scrosby/followers","following_url":"https://api.github.com/users/scrosby/following{/other_user}","gists_url":"https://api.github.com/users/scrosby/gists{/gist_id}","starred_url":"https://api.github.com/users/scrosby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scrosby/subscriptions","organizations_url":"https://api.github.com/users/scrosby/orgs","repos_url":"https://api.github.com/users/scrosby/repos","events_url":"https://api.github.com/users/scrosby/events{/privacy}","received_events_url":"https://api.github.com/users/scrosby/received_events","type":"User","site_admin":false},"html_url":"https://github.com/scrosby/Cook","description":"Fair job scheduler on Mesos for batch workloads and Spark","fork":true,"url":"https://api.github.com/repos/scrosby/Cook","forks_url":"https://api.github.com/repos/scrosby/Cook/forks","keys_url":"https://api.github.com/repos/scrosby/Cook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scrosby/Cook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scrosby/Cook/teams","hooks_url":"https://api.github.com/repos/scrosby/Cook/hooks","issue_events_url":"https://api.github.com/repos/scrosby/Cook/issues/events{/number}","events_url":"https://api.github.com/repos/scrosby/Cook/events","assignees_url":"https://api.github.com/repos/scrosby/Cook/assignees{/user}","branches_url":"https://api.github.com/repos/scrosby/Cook/branches{/branch}","tags_url":"https://api.github.com/repos/scrosby/Cook/tags","blobs_url":"https://api.github.com/repos/scrosby/Cook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scrosby/Cook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scrosby/Cook/git/refs{/sha}","trees_url":"https://api.github.com/repos/scrosby/Cook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scrosby/Cook/statuses/{sha}","languages_url":"https://api.github.com/repos/scrosby/Cook/languages","stargazers_url":"https://api.github.com/repos/scrosby/Cook/stargazers","contributors_url":"https://api.github.com/repos/scrosby/Cook/contributors","subscribers_url":"https://api.github.com/repos/scrosby/Cook/subscribers","subscription_url":"https://api.github.com/repos/scrosby/Cook/subscription","commits_url":"https://api.github.com/repos/scrosby/Cook/commits{/sha}","git_commits_url":"https://api.github.com/repos/scrosby/Cook/git/commits{/sha}","comments_url":"https://api.github.com/repos/scrosby/Cook/comments{/number}","issue_comment_url":"https://api.github.com/repos/scrosby/Cook/issues/comments{/number}","contents_url":"https://api.github.com/repos/scrosby/Cook/contents/{+path}","compare_url":"https://api.github.com/repos/scrosby/Cook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scrosby/Cook/merges","archive_url":"https://api.github.com/repos/scrosby/Cook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scrosby/Cook/downloads","issues_url":"https://api.github.com/repos/scrosby/Cook/issues{/number}","pulls_url":"https://api.github.com/repos/scrosby/Cook/pulls{/number}","milestones_url":"https://api.github.com/repos/scrosby/Cook/milestones{/number}","notifications_url":"https://api.github.com/repos/scrosby/Cook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scrosby/Cook/labels{/name}","releases_url":"https://api.github.com/repos/scrosby/Cook/releases{/id}","deployments_url":"https://api.github.com/repos/scrosby/Cook/deployments","created_at":"2018-02-15T15:13:27Z","updated_at":"2018-12-03T17:03:58Z","pushed_at":"2018-12-03T17:03:53Z","git_url":"git://github.com/scrosby/Cook.git","ssh_url":"git@github.com:scrosby/Cook.git","clone_url":"https://github.com/scrosby/Cook.git","svn_url":"https://github.com/scrosby/Cook","homepage":"","size":43077,"stargazers_count":0,"watchers_count":0,"language":"Clojure","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"twosigma:master","ref":"master","sha":"14b192bfec9d062427683dd44987510c81d616e3","user":{"login":"twosigma","id":4049181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwNDkxODE=","avatar_url":"https://avatars3.githubusercontent.com/u/4049181?v=4","gravatar_id":"","url":"https://api.github.com/users/twosigma","html_url":"https://github.com/twosigma","followers_url":"https://api.github.com/users/twosigma/followers","following_url":"https://api.github.com/users/twosigma/following{/other_user}","gists_url":"https://api.github.com/users/twosigma/gists{/gist_id}","starred_url":"https://api.github.com/users/twosigma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twosigma/subscriptions","organizations_url":"https://api.github.com/users/twosigma/orgs","repos_url":"https://api.github.com/users/twosigma/repos","events_url":"https://api.github.com/users/twosigma/events{/privacy}","received_events_url":"https://api.github.com/users/twosigma/received_events","type":"Organization","site_admin":false},"repo":{"id":42325066,"node_id":"MDEwOlJlcG9zaXRvcnk0MjMyNTA2Ng==","name":"Cook","full_name":"twosigma/Cook","private":false,"owner":{"login":"twosigma","id":4049181,"node_id":"MDEyOk9yZ2FuaXphdGlvbjQwNDkxODE=","avatar_url":"https://avatars3.githubusercontent.com/u/4049181?v=4","gravatar_id":"","url":"https://api.github.com/users/twosigma","html_url":"https://github.com/twosigma","followers_url":"https://api.github.com/users/twosigma/followers","following_url":"https://api.github.com/users/twosigma/following{/other_user}","gists_url":"https://api.github.com/users/twosigma/gists{/gist_id}","starred_url":"https://api.github.com/users/twosigma/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twosigma/subscriptions","organizations_url":"https://api.github.com/users/twosigma/orgs","repos_url":"https://api.github.com/users/twosigma/repos","events_url":"https://api.github.com/users/twosigma/events{/privacy}","received_events_url":"https://api.github.com/users/twosigma/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/twosigma/Cook","description":"Fair job scheduler on Mesos for batch workloads and Spark","fork":false,"url":"https://api.github.com/repos/twosigma/Cook","forks_url":"https://api.github.com/repos/twosigma/Cook/forks","keys_url":"https://api.github.com/repos/twosigma/Cook/keys{/key_id}","collaborators_url":"https://api.github.com/repos/twosigma/Cook/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/twosigma/Cook/teams","hooks_url":"https://api.github.com/repos/twosigma/Cook/hooks","issue_events_url":"https://api.github.com/repos/twosigma/Cook/issues/events{/number}","events_url":"https://api.github.com/repos/twosigma/Cook/events","assignees_url":"https://api.github.com/repos/twosigma/Cook/assignees{/user}","branches_url":"https://api.github.com/repos/twosigma/Cook/branches{/branch}","tags_url":"https://api.github.com/repos/twosigma/Cook/tags","blobs_url":"https://api.github.com/repos/twosigma/Cook/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/twosigma/Cook/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/twosigma/Cook/git/refs{/sha}","trees_url":"https://api.github.com/repos/twosigma/Cook/git/trees{/sha}","statuses_url":"https://api.github.com/repos/twosigma/Cook/statuses/{sha}","languages_url":"https://api.github.com/repos/twosigma/Cook/languages","stargazers_url":"https://api.github.com/repos/twosigma/Cook/stargazers","contributors_url":"https://api.github.com/repos/twosigma/Cook/contributors","subscribers_url":"https://api.github.com/repos/twosigma/Cook/subscribers","subscription_url":"https://api.github.com/repos/twosigma/Cook/subscription","commits_url":"https://api.github.com/repos/twosigma/Cook/commits{/sha}","git_commits_url":"https://api.github.com/repos/twosigma/Cook/git/commits{/sha}","comments_url":"https://api.github.com/repos/twosigma/Cook/comments{/number}","issue_comment_url":"https://api.github.com/repos/twosigma/Cook/issues/comments{/number}","contents_url":"https://api.github.com/repos/twosigma/Cook/contents/{+path}","compare_url":"https://api.github.com/repos/twosigma/Cook/compare/{base}...{head}","merges_url":"https://api.github.com/repos/twosigma/Cook/merges","archive_url":"https://api.github.com/repos/twosigma/Cook/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/twosigma/Cook/downloads","issues_url":"https://api.github.com/repos/twosigma/Cook/issues{/number}","pulls_url":"https://api.github.com/repos/twosigma/Cook/pulls{/number}","milestones_url":"https://api.github.com/repos/twosigma/Cook/milestones{/number}","notifications_url":"https://api.github.com/repos/twosigma/Cook/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/twosigma/Cook/labels{/name}","releases_url":"https://api.github.com/repos/twosigma/Cook/releases{/id}","deployments_url":"https://api.github.com/repos/twosigma/Cook/deployments","created_at":"2015-09-11T18:20:08Z","updated_at":"2018-11-30T22:39:10Z","pushed_at":"2018-12-03T17:06:49Z","git_url":"git://github.com/twosigma/Cook.git","ssh_url":"git@github.com:twosigma/Cook.git","clone_url":"https://github.com/twosigma/Cook.git","svn_url":"https://github.com/twosigma/Cook","homepage":"","size":43109,"stargazers_count":274,"watchers_count":274,"language":"Clojure","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":49,"mirror_url":null,"archived":false,"open_issues_count":99,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":49,"open_issues":99,"watchers":274,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/1044"},"html":{"href":"https://github.com/twosigma/Cook/pull/1044"},"issue":{"href":"https://api.github.com/repos/twosigma/Cook/issues/1044"},"comments":{"href":"https://api.github.com/repos/twosigma/Cook/issues/1044/comments"},"review_comments":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/1044/comments"},"review_comment":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/twosigma/Cook/pulls/1044/commits"},"statuses":{"href":"https://api.github.com/repos/twosigma/Cook/statuses/c3d0b4b603b05c1cd6b32ed7834d3d0f23c1fe88"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"pschorf"}}