Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACL-263] Caching improvements #337

Merged
merged 17 commits into from
Jan 22, 2025
Merged

[ACL-263] Caching improvements #337

merged 17 commits into from
Jan 22, 2025

Conversation

dili91
Copy link
Contributor

@dili91 dili91 commented Jan 9, 2025

Description

This PR includes 2 necessary breaking changes:

  1. It changes how the custom cache implementation works, aligning that to the other officially supported libs. By doing that, we make the library more more robust for use cases where multiple client instances are used
  2. It removes a deprecated utility to build the HPP link

Type of change

Please select multiple options if required.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have updated the gradle.properties file with the new version
  • I have updated the CHANGELOG.md file with the details of the new version
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the relevant documentation

@dili91 dili91 changed the title Caching improvements [ACL-263] Caching improvements Jan 10, 2025
@@ -182,12 +185,13 @@ public TrueLayerClientBuilder withHttpLogs(Consumer<String> logConsumer) {
* @return the instance of the client builder used
*/
public TrueLayerClientBuilder withCredentialsCaching() {
this.credentialsCache = new SimpleCredentialsCache(Clock.systemUTC());
this.credentialsCache = new InMemoryCredentialsCache(Clock.systemUTC());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we anyway need a breaking change for the new cache interface (that aligns to what PHP and .NET libs do), I took the chance to rename this to be more explicit

return MessageFormat.format("{0}:{1}:{2}", CACHE_KEY_PREFIX, clientId, bytesToHex(md5InBytes));
}

private static byte[] digest(byte[] input) {
Copy link
Contributor Author

@dili91 dili91 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using a numeric hashcode I'm using MD5. We don't really need this to be bullet-proof, so I think it's fine.

Comment on lines -14 to +8
Optional<AccessToken> getToken(RequestScopes scopes);
Optional<AccessToken> getToken(String key);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change: users of a custom cache won't have to bother computing hash keys. They will receive what the client builds, and they have the option to customise/override those if needed

@dili91 dili91 marked this pull request as ready for review January 21, 2025 18:00
@dili91 dili91 requested review from a team as code owners January 21, 2025 18:00
@dili91 dili91 merged commit fe685e2 into main Jan 22, 2025
16 of 18 checks passed
@dili91 dili91 deleted the caching-improvements branch January 22, 2025 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants