Skip to content

Client credentials caching

Andrea Di Lisio edited this page Aug 29, 2023 · 5 revisions

The library comes with options for caching client credentials, thus avoiding to call Oauth endpoints on each authenticated API invocation.

Default behavior: no cache

By default, the library does not cache any token. To enable the caching feature there are two options: using a default in-memory cache or define custom cache storage. Either way developers are not asked to provide an implementation that takes care of the expiration of the token.

Enabling the default in-memory caching

To enable the default in memory cache it's enough to invoke the withCredentialsCaching() on the client builder instance.

TrueLayerClientBuilder sut = new TrueLayerClientBuilder()
  .clientCredentials(getClientCredentials())
  .signingOptions(getSigningOptions())
  .withHttpLogs()
  .withCredentialsCaching();

Specifying a custom cache storage

To define a custom cache storage you can provide an implementation of the ICredentialsCache interface:

TrueLayerClientBuilder sut = new TrueLayerClientBuilder()
  .clientCredentials(getClientCredentials())
  .signingOptions(getSigningOptions())
  .withHttpLogs()
  .withCredentialsCaching(MyCustomCacheImpl);

You need to provide a custom cache implementation of the ICredentialsCache interface.