diff --git a/README.md b/README.md index 00bf1f6..350cd25 100644 --- a/README.md +++ b/README.md @@ -137,3 +137,7 @@ ApiClient client = ApiClient.GetApiClientWithClientCredentials(apiKey, apiSecret ``` For more examples, see unittests package. + +## `ApiClient` lifecycle + +In production applications, we recommend utilizing the `ApiClient` as a global singleton. This ensures that token caching is properly performed. diff --git a/src/main/java/com/gettyimages/api/Credentials.java b/src/main/java/com/gettyimages/api/Credentials.java index dc934ff..dcdeb5f 100644 --- a/src/main/java/com/gettyimages/api/Credentials.java +++ b/src/main/java/com/gettyimages/api/Credentials.java @@ -74,12 +74,12 @@ public static Credentials GetInstance(String apiKey, String apiSecret, String us } public Token GetAccessToken() throws SdkException { - Calendar now = Calendar.getInstance(); - now.add(Calendar.MINUTE, 5); + Calendar expirationCushion = Calendar.getInstance(); + expirationCushion.add(Calendar.MINUTE, 5); if (CredentialType != CredentialType.ClientCredentials && CredentialType != CredentialType.ResourceOwner && CredentialType != CredentialType.RefreshToken || - (accessToken != null && accessToken.getExpiration().compareTo(now.getTime()) >= 0)) { + (accessToken != null && accessToken.getExpiration().compareTo(expirationCushion.getTime()) >= 0)) { return accessToken; }