Skip to content

Client credentials caching

Andrea Di Lisio edited this page Mar 18, 2022 · 5 revisions

Default behavior: no cache

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

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);

Clone this wiki locally