Sets the
CacheManager that should be used to cache Okta REST resources, reducing round-trips to the
Okta API server and enhancing application performance.
Single JVM Applications
If your application runs on a single JVM-based applications, the
com.okta.sdk.cache.CacheManagerBuilder should be sufficient for your needs. You
create a
CacheManagerBuilder by using the
com.okta.sdk.cache.Caches utility class,
for example:
import static com.okta.sdk.cache.Caches.*;
...
Client client = Clients.builder()...
.setCacheManager(
com.okta.sdk.cache.Caches#newCacheManager().withDefaultTimeToLive(1, TimeUnit.DAYS) //general default
.withDefaultTimeToIdle(2, TimeUnit.HOURS) //general default
.withCache(
com.okta.sdk.cache.Caches#forResource(Class)(Account.class) //Account-specific cache settings
.withTimeToLive(1, TimeUnit.HOURS)
.withTimeToIdle(30, TimeUnit.MINUTES))
.withCache(
com.okta.sdk.cache.Caches#forResource(Class)(Group.class) //Group-specific cache settings
.withTimeToLive(2, TimeUnit.HOURS))
.build() //build the CacheManager
)
.build(); //build the Client
The above TTL and TTI times are just examples showing API usage - the times themselves are not
recommendations. Choose TTL and TTI times based on your application requirements.
Multi-JVM / Clustered Applications
The default
CacheManager instances returned by the
com.okta.sdk.cache.CacheManagerBuilder might not be sufficient for a
multi-instance application that runs on multiple JVMs and/or hosts/servers, as there could be cache-coherency
problems across the JVMs. See the
com.okta.sdk.cache.CacheManagerBuilderJavaDoc for additional information.
In these multi-JVM environments, you will likely want to create a simple CacheManager implementation that
wraps your distributed Caching API/product of choice and then plug that implementation in to the Okta SDK
via this method. Hazelcast is one known cluster-safe caching product, and the Okta SDK has out-of-the-box
support for this as an extension module. See the top-level class JavaDoc for a Hazelcast configuration
example.