{"action":"created","comment":{"url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/comments/102507065","pull_request_review_id":23264490,"id":102507065,"diff_hunk":"@@ -0,0 +1,206 @@\n+package org.eclipse.jgit.internal.storage.dfs;\n+\n+import com.github.benmanes.caffeine.cache.*;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.io.IOException;\n+import java.util.Objects;\n+\n+public final class DfsBlockCaffeineCache extends DfsBlockCache {\n+\n+    private static final Logger log = LoggerFactory.getLogger(DfsBlockCaffeineCache.class);\n+\n+    /** Pack files smaller than this size can be copied through the cache. */\n+    private final long maxStreamThroughCache;\n+\n+    /**\n+     * Suggested block size to read from pack files in bytes.\n+     * <p>\n+     * If a pack file does not have a native block size, this size will be used.\n+     * <p>\n+     * If a pack file has a native size, a whole multiple of the native size\n+     * will be used until it matches this size.\n+     * <p>\n+     * The value for blockSize must be a power of 2 and no less than 512.\n+     */\n+    private final int blockSize;\n+\n+    /** Cache of pack files, indexed by description. */\n+    private final Cache<DfsPackDescription, DfsPackFile> packFileCache;\n+\n+    /** Cache of Dfs blocks. */\n+    private final Cache<DfsPackKeyWithPosition, Ref> dfsBlockCache;\n+\n+    public static void reconfigure(final DfsBlockCaffeineCacheConfig cacheConfig) {\n+        DfsBlockCache.setInstance(new DfsBlockCaffeineCache(cacheConfig));\n+    }\n+\n+    private DfsBlockCaffeineCache(DfsBlockCaffeineCacheConfig cacheConfig) {\n+        maxStreamThroughCache = (long) (cacheConfig.getCacheMaximumSize() * cacheConfig.getStreamRatio());\n+\n+        blockSize = cacheConfig.getBlockSize();\n+\n+        // TODO: register the cache and expose the stats\n+        // the estimated retained bytes is estimated based on the fields each object contains\n+        packFileCache = Caffeine.newBuilder()\n+                .removalListener((DfsPackDescription description, DfsPackFile packFile, RemovalCause cause) -> {\n+                    if (packFile != null) {\n+                        log.debug(\"PackFile {} is removed because it {}\", packFile.getPackName(), cause);\n+                        packFile.key.cachedSize.set(0);","path":"org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/DfsBlockCaffeineCache.java","position":50,"original_position":50,"commit_id":"2f2ed77f10172c6f270aecf260651651cb252f6a","original_commit_id":"2f2ed77f10172c6f270aecf260651651cb252f6a","user":{"login":"JiahuiJiang","id":13910193,"avatar_url":"https://avatars.githubusercontent.com/u/13910193?v=3","gravatar_id":"","url":"https://api.github.com/users/JiahuiJiang","html_url":"https://github.com/JiahuiJiang","followers_url":"https://api.github.com/users/JiahuiJiang/followers","following_url":"https://api.github.com/users/JiahuiJiang/following{/other_user}","gists_url":"https://api.github.com/users/JiahuiJiang/gists{/gist_id}","starred_url":"https://api.github.com/users/JiahuiJiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiahuiJiang/subscriptions","organizations_url":"https://api.github.com/users/JiahuiJiang/orgs","repos_url":"https://api.github.com/users/JiahuiJiang/repos","events_url":"https://api.github.com/users/JiahuiJiang/events{/privacy}","received_events_url":"https://api.github.com/users/JiahuiJiang/received_events","type":"User","site_admin":false},"body":"updated with one cache + 2 maps method","created_at":"2017-02-22T16:30:19Z","updated_at":"2017-02-22T16:30:19Z","html_url":"https://github.com/JiahuiJiang/jgit/pull/2#discussion_r102507065","pull_request_url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2","_links":{"self":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/comments/102507065"},"html":{"href":"https://github.com/JiahuiJiang/jgit/pull/2#discussion_r102507065"},"pull_request":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2"}}},"pull_request":{"url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2","id":106658746,"html_url":"https://github.com/JiahuiJiang/jgit/pull/2","diff_url":"https://github.com/JiahuiJiang/jgit/pull/2.diff","patch_url":"https://github.com/JiahuiJiang/jgit/pull/2.patch","issue_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues/2","number":2,"state":"open","locked":false,"title":"Implement DfsBlockCache with Caffeine Cache","user":{"login":"JiahuiJiang","id":13910193,"avatar_url":"https://avatars.githubusercontent.com/u/13910193?v=3","gravatar_id":"","url":"https://api.github.com/users/JiahuiJiang","html_url":"https://github.com/JiahuiJiang","followers_url":"https://api.github.com/users/JiahuiJiang/followers","following_url":"https://api.github.com/users/JiahuiJiang/following{/other_user}","gists_url":"https://api.github.com/users/JiahuiJiang/gists{/gist_id}","starred_url":"https://api.github.com/users/JiahuiJiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiahuiJiang/subscriptions","organizations_url":"https://api.github.com/users/JiahuiJiang/orgs","repos_url":"https://api.github.com/users/JiahuiJiang/repos","events_url":"https://api.github.com/users/JiahuiJiang/events{/privacy}","received_events_url":"https://api.github.com/users/JiahuiJiang/received_events","type":"User","site_admin":false},"body":"DO NOT MERGE\r\n\r\nNote: This should live in the project that wants to pass this implementation in, for now to make it\r\neasier to review.","created_at":"2017-02-17T02:48:52Z","updated_at":"2017-02-22T16:30:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3526bed1ad1a0d5fc62288f2729245e68ddf0edd","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2/commits","review_comments_url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2/comments","review_comment_url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/comments{/number}","comments_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues/2/comments","statuses_url":"https://api.github.com/repos/JiahuiJiang/jgit/statuses/2f2ed77f10172c6f270aecf260651651cb252f6a","head":{"label":"JiahuiJiang:jj/caffeine-implementation","ref":"jj/caffeine-implementation","sha":"2f2ed77f10172c6f270aecf260651651cb252f6a","user":{"login":"JiahuiJiang","id":13910193,"avatar_url":"https://avatars.githubusercontent.com/u/13910193?v=3","gravatar_id":"","url":"https://api.github.com/users/JiahuiJiang","html_url":"https://github.com/JiahuiJiang","followers_url":"https://api.github.com/users/JiahuiJiang/followers","following_url":"https://api.github.com/users/JiahuiJiang/following{/other_user}","gists_url":"https://api.github.com/users/JiahuiJiang/gists{/gist_id}","starred_url":"https://api.github.com/users/JiahuiJiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiahuiJiang/subscriptions","organizations_url":"https://api.github.com/users/JiahuiJiang/orgs","repos_url":"https://api.github.com/users/JiahuiJiang/repos","events_url":"https://api.github.com/users/JiahuiJiang/events{/privacy}","received_events_url":"https://api.github.com/users/JiahuiJiang/received_events","type":"User","site_admin":false},"repo":{"id":82248122,"name":"jgit","full_name":"JiahuiJiang/jgit","owner":{"login":"JiahuiJiang","id":13910193,"avatar_url":"https://avatars.githubusercontent.com/u/13910193?v=3","gravatar_id":"","url":"https://api.github.com/users/JiahuiJiang","html_url":"https://github.com/JiahuiJiang","followers_url":"https://api.github.com/users/JiahuiJiang/followers","following_url":"https://api.github.com/users/JiahuiJiang/following{/other_user}","gists_url":"https://api.github.com/users/JiahuiJiang/gists{/gist_id}","starred_url":"https://api.github.com/users/JiahuiJiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiahuiJiang/subscriptions","organizations_url":"https://api.github.com/users/JiahuiJiang/orgs","repos_url":"https://api.github.com/users/JiahuiJiang/repos","events_url":"https://api.github.com/users/JiahuiJiang/events{/privacy}","received_events_url":"https://api.github.com/users/JiahuiJiang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JiahuiJiang/jgit","description":"JGit project repository (jgit)","fork":true,"url":"https://api.github.com/repos/JiahuiJiang/jgit","forks_url":"https://api.github.com/repos/JiahuiJiang/jgit/forks","keys_url":"https://api.github.com/repos/JiahuiJiang/jgit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JiahuiJiang/jgit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JiahuiJiang/jgit/teams","hooks_url":"https://api.github.com/repos/JiahuiJiang/jgit/hooks","issue_events_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues/events{/number}","events_url":"https://api.github.com/repos/JiahuiJiang/jgit/events","assignees_url":"https://api.github.com/repos/JiahuiJiang/jgit/assignees{/user}","branches_url":"https://api.github.com/repos/JiahuiJiang/jgit/branches{/branch}","tags_url":"https://api.github.com/repos/JiahuiJiang/jgit/tags","blobs_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/refs{/sha}","trees_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JiahuiJiang/jgit/statuses/{sha}","languages_url":"https://api.github.com/repos/JiahuiJiang/jgit/languages","stargazers_url":"https://api.github.com/repos/JiahuiJiang/jgit/stargazers","contributors_url":"https://api.github.com/repos/JiahuiJiang/jgit/contributors","subscribers_url":"https://api.github.com/repos/JiahuiJiang/jgit/subscribers","subscription_url":"https://api.github.com/repos/JiahuiJiang/jgit/subscription","commits_url":"https://api.github.com/repos/JiahuiJiang/jgit/commits{/sha}","git_commits_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/commits{/sha}","comments_url":"https://api.github.com/repos/JiahuiJiang/jgit/comments{/number}","issue_comment_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues/comments{/number}","contents_url":"https://api.github.com/repos/JiahuiJiang/jgit/contents/{+path}","compare_url":"https://api.github.com/repos/JiahuiJiang/jgit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JiahuiJiang/jgit/merges","archive_url":"https://api.github.com/repos/JiahuiJiang/jgit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JiahuiJiang/jgit/downloads","issues_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues{/number}","pulls_url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls{/number}","milestones_url":"https://api.github.com/repos/JiahuiJiang/jgit/milestones{/number}","notifications_url":"https://api.github.com/repos/JiahuiJiang/jgit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JiahuiJiang/jgit/labels{/name}","releases_url":"https://api.github.com/repos/JiahuiJiang/jgit/releases{/id}","deployments_url":"https://api.github.com/repos/JiahuiJiang/jgit/deployments","created_at":"2017-02-17T02:25:55Z","updated_at":"2017-02-17T02:26:04Z","pushed_at":"2017-02-21T02:40:09Z","git_url":"git://github.com/JiahuiJiang/jgit.git","ssh_url":"git@github.com:JiahuiJiang/jgit.git","clone_url":"https://github.com/JiahuiJiang/jgit.git","svn_url":"https://github.com/JiahuiJiang/jgit","homepage":"http://eclipse.org/jgit","size":16283,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"JiahuiJiang:jj/new-cache","ref":"jj/new-cache","sha":"dbdc658382b0dabe40103303c4eb6adbdc6bc57f","user":{"login":"JiahuiJiang","id":13910193,"avatar_url":"https://avatars.githubusercontent.com/u/13910193?v=3","gravatar_id":"","url":"https://api.github.com/users/JiahuiJiang","html_url":"https://github.com/JiahuiJiang","followers_url":"https://api.github.com/users/JiahuiJiang/followers","following_url":"https://api.github.com/users/JiahuiJiang/following{/other_user}","gists_url":"https://api.github.com/users/JiahuiJiang/gists{/gist_id}","starred_url":"https://api.github.com/users/JiahuiJiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiahuiJiang/subscriptions","organizations_url":"https://api.github.com/users/JiahuiJiang/orgs","repos_url":"https://api.github.com/users/JiahuiJiang/repos","events_url":"https://api.github.com/users/JiahuiJiang/events{/privacy}","received_events_url":"https://api.github.com/users/JiahuiJiang/received_events","type":"User","site_admin":false},"repo":{"id":82248122,"name":"jgit","full_name":"JiahuiJiang/jgit","owner":{"login":"JiahuiJiang","id":13910193,"avatar_url":"https://avatars.githubusercontent.com/u/13910193?v=3","gravatar_id":"","url":"https://api.github.com/users/JiahuiJiang","html_url":"https://github.com/JiahuiJiang","followers_url":"https://api.github.com/users/JiahuiJiang/followers","following_url":"https://api.github.com/users/JiahuiJiang/following{/other_user}","gists_url":"https://api.github.com/users/JiahuiJiang/gists{/gist_id}","starred_url":"https://api.github.com/users/JiahuiJiang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JiahuiJiang/subscriptions","organizations_url":"https://api.github.com/users/JiahuiJiang/orgs","repos_url":"https://api.github.com/users/JiahuiJiang/repos","events_url":"https://api.github.com/users/JiahuiJiang/events{/privacy}","received_events_url":"https://api.github.com/users/JiahuiJiang/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/JiahuiJiang/jgit","description":"JGit project repository (jgit)","fork":true,"url":"https://api.github.com/repos/JiahuiJiang/jgit","forks_url":"https://api.github.com/repos/JiahuiJiang/jgit/forks","keys_url":"https://api.github.com/repos/JiahuiJiang/jgit/keys{/key_id}","collaborators_url":"https://api.github.com/repos/JiahuiJiang/jgit/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/JiahuiJiang/jgit/teams","hooks_url":"https://api.github.com/repos/JiahuiJiang/jgit/hooks","issue_events_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues/events{/number}","events_url":"https://api.github.com/repos/JiahuiJiang/jgit/events","assignees_url":"https://api.github.com/repos/JiahuiJiang/jgit/assignees{/user}","branches_url":"https://api.github.com/repos/JiahuiJiang/jgit/branches{/branch}","tags_url":"https://api.github.com/repos/JiahuiJiang/jgit/tags","blobs_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/refs{/sha}","trees_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/trees{/sha}","statuses_url":"https://api.github.com/repos/JiahuiJiang/jgit/statuses/{sha}","languages_url":"https://api.github.com/repos/JiahuiJiang/jgit/languages","stargazers_url":"https://api.github.com/repos/JiahuiJiang/jgit/stargazers","contributors_url":"https://api.github.com/repos/JiahuiJiang/jgit/contributors","subscribers_url":"https://api.github.com/repos/JiahuiJiang/jgit/subscribers","subscription_url":"https://api.github.com/repos/JiahuiJiang/jgit/subscription","commits_url":"https://api.github.com/repos/JiahuiJiang/jgit/commits{/sha}","git_commits_url":"https://api.github.com/repos/JiahuiJiang/jgit/git/commits{/sha}","comments_url":"https://api.github.com/repos/JiahuiJiang/jgit/comments{/number}","issue_comment_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues/comments{/number}","contents_url":"https://api.github.com/repos/JiahuiJiang/jgit/contents/{+path}","compare_url":"https://api.github.com/repos/JiahuiJiang/jgit/compare/{base}...{head}","merges_url":"https://api.github.com/repos/JiahuiJiang/jgit/merges","archive_url":"https://api.github.com/repos/JiahuiJiang/jgit/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/JiahuiJiang/jgit/downloads","issues_url":"https://api.github.com/repos/JiahuiJiang/jgit/issues{/number}","pulls_url":"https://api.github.com/repos/JiahuiJiang/jgit/pulls{/number}","milestones_url":"https://api.github.com/repos/JiahuiJiang/jgit/milestones{/number}","notifications_url":"https://api.github.com/repos/JiahuiJiang/jgit/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/JiahuiJiang/jgit/labels{/name}","releases_url":"https://api.github.com/repos/JiahuiJiang/jgit/releases{/id}","deployments_url":"https://api.github.com/repos/JiahuiJiang/jgit/deployments","created_at":"2017-02-17T02:25:55Z","updated_at":"2017-02-17T02:26:04Z","pushed_at":"2017-02-21T02:40:09Z","git_url":"git://github.com/JiahuiJiang/jgit.git","ssh_url":"git@github.com:JiahuiJiang/jgit.git","clone_url":"https://github.com/JiahuiJiang/jgit.git","svn_url":"https://github.com/JiahuiJiang/jgit","homepage":"http://eclipse.org/jgit","size":16283,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2"},"html":{"href":"https://github.com/JiahuiJiang/jgit/pull/2"},"issue":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/issues/2"},"comments":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/issues/2/comments"},"review_comments":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2/comments"},"review_comment":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/pulls/2/commits"},"statuses":{"href":"https://api.github.com/repos/JiahuiJiang/jgit/statuses/2f2ed77f10172c6f270aecf260651651cb252f6a"}}}}
{"actor":{"display_login":"JiahuiJiang"}}