@@ -143,6 +143,7 @@ public class BitbucketCloudApiClient implements BitbucketApi {
143
143
private static final Cache <String , BitbucketTeam > cachedTeam = new Cache <>(6 , HOURS );
144
144
private static final Cache <String , AvatarImage > cachedAvatar = new Cache <>(6 , HOURS );
145
145
private static final Cache <String , List <BitbucketCloudRepository >> cachedRepositories = new Cache <>(3 , HOURS );
146
+ private static final Cache <String , BitbucketCloudCommit > cachedCommits = new Cache <>(24 , HOURS );
146
147
private transient BitbucketRepository cachedRepository ;
147
148
private transient String cachedDefaultBranch ;
148
149
@@ -156,12 +157,14 @@ public static List<String> stats() {
156
157
List <String > stats = new ArrayList <>();
157
158
stats .add ("Team: " + cachedTeam .stats ().toString ());
158
159
stats .add ("Repositories : " + cachedRepositories .stats ().toString ());
160
+ stats .add ("Commits: " + cachedCommits .stats ().toString ());
159
161
return stats ;
160
162
}
161
163
162
164
public static void clearCaches () {
163
165
cachedTeam .evictAll ();
164
166
cachedRepositories .evictAll ();
167
+ cachedCommits .evictAll ();
165
168
}
166
169
167
170
@ Deprecated
@@ -519,22 +522,35 @@ public List<BitbucketCloudBranch> getBranchesByRef(String nodePath) throws IOExc
519
522
@ Override
520
523
@ CheckForNull
521
524
public BitbucketCommit resolveCommit (@ NonNull String hash ) throws IOException , InterruptedException {
522
- String url = UriTemplate .fromTemplate (REPO_URL_TEMPLATE + "/commit/{hash}" )
523
- .set ("owner" , owner )
524
- .set ("repo" , repositoryName )
525
- .set ("hash" , hash )
526
- .expand ();
527
- String response ;
525
+ final String url = UriTemplate .fromTemplate (REPO_URL_TEMPLATE + "/commit/{hash}" )
526
+ .set ("owner" , owner )
527
+ .set ("repo" , repositoryName )
528
+ .set ("hash" , hash )
529
+ .expand ();
530
+
531
+ Callable <BitbucketCloudCommit > request = () -> {
532
+ String response ;
533
+ try {
534
+ response = getRequest (url );
535
+ } catch (FileNotFoundException e ) {
536
+ return null ;
537
+ }
538
+ try {
539
+ return JsonParser .toJava (response , BitbucketCloudCommit .class );
540
+ } catch (IOException e ) {
541
+ throw new IOException ("I/O error when parsing response from URL: " + url , e );
542
+ }
543
+ };
544
+
528
545
try {
529
- response = getRequest (url );
530
- } catch (FileNotFoundException e ) {
546
+ if (enableCache ) {
547
+ return cachedCommits .get (hash , request );
548
+ } else {
549
+ return request .call ();
550
+ }
551
+ } catch (Exception ex ) {
531
552
return null ;
532
553
}
533
- try {
534
- return JsonParser .toJava (response , BitbucketCloudCommit .class );
535
- } catch (IOException e ) {
536
- throw new IOException ("I/O error when parsing response from URL: " + url , e );
537
- }
538
554
}
539
555
540
556
/**
0 commit comments