{"action":"created","comment":{"url":"https://api.github.com/repos/datanerds-io/lack/pulls/comments/60729960","id":60729960,"diff_hunk":"@@ -0,0 +1,62 @@\n+package io.datanerds.lack;\n+\n+import com.google.common.cache.Cache;\n+import com.google.common.cache.CacheBuilder;\n+import io.datanerds.lack.cassandra.LackConfig;\n+\n+import java.util.concurrent.TimeUnit;\n+\n+import static io.datanerds.lack.Messages.MESSAGE_ACQUIRE;\n+\n+public class CachedLack extends Lack {\n+\n+    private final Cache<String, Boolean> cache;\n+\n+    public CachedLack(LackConfig config, String owner, Cache<String, Boolean> cache) {\n+        super(config, owner);\n+        this.cache = cache;\n+    }\n+\n+    public CachedLack(LackConfig config, String owner, long size) {\n+        this(config, owner, CacheBuilder.newBuilder()\n+                .maximumSize(size)\n+                .expireAfterWrite(config.ttlInSeconds, TimeUnit.SECONDS)\n+                .build());\n+    }\n+\n+    @Override\n+    public void acquire(String resource) throws LackException {\n+        Boolean locked = cache.getIfPresent(resource);\n+        if (locked != null && locked) {\n+            throw new LackException(String.format(MESSAGE_ACQUIRE, resource));\n+        }\n+\n+        try {","path":"lack/src/main/java/io/datanerds/lack/CachedLack.java","position":34,"original_position":34,"commit_id":"43e86c6132a624ac757fda2929f074691cf1d4bd","original_commit_id":"43e86c6132a624ac757fda2929f074691cf1d4bd","user":{"login":"larsp","id":2473475,"avatar_url":"https://avatars.githubusercontent.com/u/2473475?v=3","gravatar_id":"","url":"https://api.github.com/users/larsp","html_url":"https://github.com/larsp","followers_url":"https://api.github.com/users/larsp/followers","following_url":"https://api.github.com/users/larsp/following{/other_user}","gists_url":"https://api.github.com/users/larsp/gists{/gist_id}","starred_url":"https://api.github.com/users/larsp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/larsp/subscriptions","organizations_url":"https://api.github.com/users/larsp/orgs","repos_url":"https://api.github.com/users/larsp/repos","events_url":"https://api.github.com/users/larsp/events{/privacy}","received_events_url":"https://api.github.com/users/larsp/received_events","type":"User","site_admin":false},"body":"The try catch can be removed","created_at":"2016-04-22T12:21:51Z","updated_at":"2016-04-22T12:21:51Z","html_url":"https://github.com/datanerds-io/lack/pull/3#discussion_r60729960","pull_request_url":"https://api.github.com/repos/datanerds-io/lack/pulls/3","_links":{"self":{"href":"https://api.github.com/repos/datanerds-io/lack/pulls/comments/60729960"},"html":{"href":"https://github.com/datanerds-io/lack/pull/3#discussion_r60729960"},"pull_request":{"href":"https://api.github.com/repos/datanerds-io/lack/pulls/3"}}},"pull_request":{"url":"https://api.github.com/repos/datanerds-io/lack/pulls/3","id":65071370,"html_url":"https://github.com/datanerds-io/lack/pull/3","diff_url":"https://github.com/datanerds-io/lack/pull/3.diff","patch_url":"https://github.com/datanerds-io/lack/pull/3.patch","issue_url":"https://api.github.com/repos/datanerds-io/lack/issues/3","number":3,"state":"open","locked":false,"title":"Use an object specific local cache for faster repeated queries.","user":{"login":"dguenms","id":5592111,"avatar_url":"https://avatars.githubusercontent.com/u/5592111?v=3","gravatar_id":"","url":"https://api.github.com/users/dguenms","html_url":"https://github.com/dguenms","followers_url":"https://api.github.com/users/dguenms/followers","following_url":"https://api.github.com/users/dguenms/following{/other_user}","gists_url":"https://api.github.com/users/dguenms/gists{/gist_id}","starred_url":"https://api.github.com/users/dguenms/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dguenms/subscriptions","organizations_url":"https://api.github.com/users/dguenms/orgs","repos_url":"https://api.github.com/users/dguenms/repos","events_url":"https://api.github.com/users/dguenms/events{/privacy}","received_events_url":"https://api.github.com/users/dguenms/received_events","type":"User","site_admin":false},"body":"- located in new CachedLack subclass to make cache use optional\r\n- minimal changes to Lack class to allow subclassing\r\n- cache is local and specific to one Lack instance (objects sharing the same connection do not share the cache)\r\n- using Guava Cache implementation\r\n- Lack.acquire(resource) is performance critical if C* queries are required for repeated queries\r\n- local cache can be used to answer question if same instance was used to acquire/renew the lock, no C* query required\r\n- if the cache does not know the resource, fallback to superclass, same with renew/release\r\n- cache uses both size and time based eviction, same TTL as C* lock configuration\r\n- tests mirror behavior specified in the Lack test specification and make sure the cache is used correctly","created_at":"2016-04-03T15:25:18Z","updated_at":"2016-04-22T12:21:51Z","closed_at":null,"merged_at":null,"merge_commit_sha":"960ffab323d94afefcec0528d3b3878bebe497ed","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/datanerds-io/lack/pulls/3/commits","review_comments_url":"https://api.github.com/repos/datanerds-io/lack/pulls/3/comments","review_comment_url":"https://api.github.com/repos/datanerds-io/lack/pulls/comments{/number}","comments_url":"https://api.github.com/repos/datanerds-io/lack/issues/3/comments","statuses_url":"https://api.github.com/repos/datanerds-io/lack/statuses/43e86c6132a624ac757fda2929f074691cf1d4bd","head":{"label":"datanerds-io:feature/local-cache","ref":"feature/local-cache","sha":"43e86c6132a624ac757fda2929f074691cf1d4bd","user":{"login":"datanerds-io","id":13678868,"avatar_url":"https://avatars.githubusercontent.com/u/13678868?v=3","gravatar_id":"","url":"https://api.github.com/users/datanerds-io","html_url":"https://github.com/datanerds-io","followers_url":"https://api.github.com/users/datanerds-io/followers","following_url":"https://api.github.com/users/datanerds-io/following{/other_user}","gists_url":"https://api.github.com/users/datanerds-io/gists{/gist_id}","starred_url":"https://api.github.com/users/datanerds-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datanerds-io/subscriptions","organizations_url":"https://api.github.com/users/datanerds-io/orgs","repos_url":"https://api.github.com/users/datanerds-io/repos","events_url":"https://api.github.com/users/datanerds-io/events{/privacy}","received_events_url":"https://api.github.com/users/datanerds-io/received_events","type":"Organization","site_admin":false},"repo":{"id":53615697,"name":"lack","full_name":"datanerds-io/lack","owner":{"login":"datanerds-io","id":13678868,"avatar_url":"https://avatars.githubusercontent.com/u/13678868?v=3","gravatar_id":"","url":"https://api.github.com/users/datanerds-io","html_url":"https://github.com/datanerds-io","followers_url":"https://api.github.com/users/datanerds-io/followers","following_url":"https://api.github.com/users/datanerds-io/following{/other_user}","gists_url":"https://api.github.com/users/datanerds-io/gists{/gist_id}","starred_url":"https://api.github.com/users/datanerds-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datanerds-io/subscriptions","organizations_url":"https://api.github.com/users/datanerds-io/orgs","repos_url":"https://api.github.com/users/datanerds-io/repos","events_url":"https://api.github.com/users/datanerds-io/events{/privacy}","received_events_url":"https://api.github.com/users/datanerds-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/datanerds-io/lack","description":"LACK is a simple consensus API on top of cassandra","fork":false,"url":"https://api.github.com/repos/datanerds-io/lack","forks_url":"https://api.github.com/repos/datanerds-io/lack/forks","keys_url":"https://api.github.com/repos/datanerds-io/lack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datanerds-io/lack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datanerds-io/lack/teams","hooks_url":"https://api.github.com/repos/datanerds-io/lack/hooks","issue_events_url":"https://api.github.com/repos/datanerds-io/lack/issues/events{/number}","events_url":"https://api.github.com/repos/datanerds-io/lack/events","assignees_url":"https://api.github.com/repos/datanerds-io/lack/assignees{/user}","branches_url":"https://api.github.com/repos/datanerds-io/lack/branches{/branch}","tags_url":"https://api.github.com/repos/datanerds-io/lack/tags","blobs_url":"https://api.github.com/repos/datanerds-io/lack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datanerds-io/lack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datanerds-io/lack/git/refs{/sha}","trees_url":"https://api.github.com/repos/datanerds-io/lack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datanerds-io/lack/statuses/{sha}","languages_url":"https://api.github.com/repos/datanerds-io/lack/languages","stargazers_url":"https://api.github.com/repos/datanerds-io/lack/stargazers","contributors_url":"https://api.github.com/repos/datanerds-io/lack/contributors","subscribers_url":"https://api.github.com/repos/datanerds-io/lack/subscribers","subscription_url":"https://api.github.com/repos/datanerds-io/lack/subscription","commits_url":"https://api.github.com/repos/datanerds-io/lack/commits{/sha}","git_commits_url":"https://api.github.com/repos/datanerds-io/lack/git/commits{/sha}","comments_url":"https://api.github.com/repos/datanerds-io/lack/comments{/number}","issue_comment_url":"https://api.github.com/repos/datanerds-io/lack/issues/comments{/number}","contents_url":"https://api.github.com/repos/datanerds-io/lack/contents/{+path}","compare_url":"https://api.github.com/repos/datanerds-io/lack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datanerds-io/lack/merges","archive_url":"https://api.github.com/repos/datanerds-io/lack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datanerds-io/lack/downloads","issues_url":"https://api.github.com/repos/datanerds-io/lack/issues{/number}","pulls_url":"https://api.github.com/repos/datanerds-io/lack/pulls{/number}","milestones_url":"https://api.github.com/repos/datanerds-io/lack/milestones{/number}","notifications_url":"https://api.github.com/repos/datanerds-io/lack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datanerds-io/lack/labels{/name}","releases_url":"https://api.github.com/repos/datanerds-io/lack/releases{/id}","deployments_url":"https://api.github.com/repos/datanerds-io/lack/deployments","created_at":"2016-03-10T20:45:43Z","updated_at":"2016-03-24T08:49:04Z","pushed_at":"2016-04-03T15:25:19Z","git_url":"git://github.com/datanerds-io/lack.git","ssh_url":"git@github.com:datanerds-io/lack.git","clone_url":"https://github.com/datanerds-io/lack.git","svn_url":"https://github.com/datanerds-io/lack","homepage":null,"size":21,"stargazers_count":5,"watchers_count":5,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":5,"default_branch":"develop"}},"base":{"label":"datanerds-io:develop","ref":"develop","sha":"17617fc62c3d766cb29f6b40b50819ddbbbfcc59","user":{"login":"datanerds-io","id":13678868,"avatar_url":"https://avatars.githubusercontent.com/u/13678868?v=3","gravatar_id":"","url":"https://api.github.com/users/datanerds-io","html_url":"https://github.com/datanerds-io","followers_url":"https://api.github.com/users/datanerds-io/followers","following_url":"https://api.github.com/users/datanerds-io/following{/other_user}","gists_url":"https://api.github.com/users/datanerds-io/gists{/gist_id}","starred_url":"https://api.github.com/users/datanerds-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datanerds-io/subscriptions","organizations_url":"https://api.github.com/users/datanerds-io/orgs","repos_url":"https://api.github.com/users/datanerds-io/repos","events_url":"https://api.github.com/users/datanerds-io/events{/privacy}","received_events_url":"https://api.github.com/users/datanerds-io/received_events","type":"Organization","site_admin":false},"repo":{"id":53615697,"name":"lack","full_name":"datanerds-io/lack","owner":{"login":"datanerds-io","id":13678868,"avatar_url":"https://avatars.githubusercontent.com/u/13678868?v=3","gravatar_id":"","url":"https://api.github.com/users/datanerds-io","html_url":"https://github.com/datanerds-io","followers_url":"https://api.github.com/users/datanerds-io/followers","following_url":"https://api.github.com/users/datanerds-io/following{/other_user}","gists_url":"https://api.github.com/users/datanerds-io/gists{/gist_id}","starred_url":"https://api.github.com/users/datanerds-io/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/datanerds-io/subscriptions","organizations_url":"https://api.github.com/users/datanerds-io/orgs","repos_url":"https://api.github.com/users/datanerds-io/repos","events_url":"https://api.github.com/users/datanerds-io/events{/privacy}","received_events_url":"https://api.github.com/users/datanerds-io/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/datanerds-io/lack","description":"LACK is a simple consensus API on top of cassandra","fork":false,"url":"https://api.github.com/repos/datanerds-io/lack","forks_url":"https://api.github.com/repos/datanerds-io/lack/forks","keys_url":"https://api.github.com/repos/datanerds-io/lack/keys{/key_id}","collaborators_url":"https://api.github.com/repos/datanerds-io/lack/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/datanerds-io/lack/teams","hooks_url":"https://api.github.com/repos/datanerds-io/lack/hooks","issue_events_url":"https://api.github.com/repos/datanerds-io/lack/issues/events{/number}","events_url":"https://api.github.com/repos/datanerds-io/lack/events","assignees_url":"https://api.github.com/repos/datanerds-io/lack/assignees{/user}","branches_url":"https://api.github.com/repos/datanerds-io/lack/branches{/branch}","tags_url":"https://api.github.com/repos/datanerds-io/lack/tags","blobs_url":"https://api.github.com/repos/datanerds-io/lack/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/datanerds-io/lack/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/datanerds-io/lack/git/refs{/sha}","trees_url":"https://api.github.com/repos/datanerds-io/lack/git/trees{/sha}","statuses_url":"https://api.github.com/repos/datanerds-io/lack/statuses/{sha}","languages_url":"https://api.github.com/repos/datanerds-io/lack/languages","stargazers_url":"https://api.github.com/repos/datanerds-io/lack/stargazers","contributors_url":"https://api.github.com/repos/datanerds-io/lack/contributors","subscribers_url":"https://api.github.com/repos/datanerds-io/lack/subscribers","subscription_url":"https://api.github.com/repos/datanerds-io/lack/subscription","commits_url":"https://api.github.com/repos/datanerds-io/lack/commits{/sha}","git_commits_url":"https://api.github.com/repos/datanerds-io/lack/git/commits{/sha}","comments_url":"https://api.github.com/repos/datanerds-io/lack/comments{/number}","issue_comment_url":"https://api.github.com/repos/datanerds-io/lack/issues/comments{/number}","contents_url":"https://api.github.com/repos/datanerds-io/lack/contents/{+path}","compare_url":"https://api.github.com/repos/datanerds-io/lack/compare/{base}...{head}","merges_url":"https://api.github.com/repos/datanerds-io/lack/merges","archive_url":"https://api.github.com/repos/datanerds-io/lack/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/datanerds-io/lack/downloads","issues_url":"https://api.github.com/repos/datanerds-io/lack/issues{/number}","pulls_url":"https://api.github.com/repos/datanerds-io/lack/pulls{/number}","milestones_url":"https://api.github.com/repos/datanerds-io/lack/milestones{/number}","notifications_url":"https://api.github.com/repos/datanerds-io/lack/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/datanerds-io/lack/labels{/name}","releases_url":"https://api.github.com/repos/datanerds-io/lack/releases{/id}","deployments_url":"https://api.github.com/repos/datanerds-io/lack/deployments","created_at":"2016-03-10T20:45:43Z","updated_at":"2016-03-24T08:49:04Z","pushed_at":"2016-04-03T15:25:19Z","git_url":"git://github.com/datanerds-io/lack.git","ssh_url":"git@github.com:datanerds-io/lack.git","clone_url":"https://github.com/datanerds-io/lack.git","svn_url":"https://github.com/datanerds-io/lack","homepage":null,"size":21,"stargazers_count":5,"watchers_count":5,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":5,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/datanerds-io/lack/pulls/3"},"html":{"href":"https://github.com/datanerds-io/lack/pull/3"},"issue":{"href":"https://api.github.com/repos/datanerds-io/lack/issues/3"},"comments":{"href":"https://api.github.com/repos/datanerds-io/lack/issues/3/comments"},"review_comments":{"href":"https://api.github.com/repos/datanerds-io/lack/pulls/3/comments"},"review_comment":{"href":"https://api.github.com/repos/datanerds-io/lack/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/datanerds-io/lack/pulls/3/commits"},"statuses":{"href":"https://api.github.com/repos/datanerds-io/lack/statuses/43e86c6132a624ac757fda2929f074691cf1d4bd"}}}}