Interface CacheManagerBuilder

All Known Implementing Classes:
DefaultCacheManagerBuilder

public interface CacheManagerBuilder
Builder for creating simple CacheManager instances suitable for SINGLE-JVM APPLICATIONS. If your application is deployed (mirrored or clustered) across multiple JVMs, you might not want to use this builder and use your own clusterable CacheManager implementation instead. See Clustering below. Clustering The default CacheManager instances created by this Builder DO NOT SUPPORT CLUSTERING.

If you use this Builder and your application is deployed on multiple JVMs, each of your application instances will have their own local cache of Okta data. Depending on your application requirements, and your cache TTL and TTI settings, this could introduce a significant difference in cached data seen by your application instances, which would likely impact user management behavior. For example, one application instance could see an account as ENABLED, but the other application instance could see it as DISABLED.

For some applications, this discrepancy might be an acceptable trade-off, especially if you configure timeToIdle and timeToLive settings low enough. For example, maybe a TTL of 5 or 10 minutes is an acceptable time to see 'stale' account data. For other applications, this might not be acceptable. If it is acceptable, configuring the timeToIdle and timeToLive settings will allow you to fine-tune how much variance you allow.

However, if you are concerned about this difference in data and you want the Okta SDK's cache to be coherent across your application nodes (typically a good thing to have), it is strongly recommended that you do not use this Builder and instead configure the Okta SDK with a clustered CacheManager implementation of your choosing. This approach still gives you excellent performance improvements and ensures that your cached data is coherent (seen as the same) across all of your application instances.

This comes with an increased cost of course: setting up a caching product and/or cluster. However, this is not much of a problem in practice: most multi-instance applications already leverage caching clusters for their own application needs. In these environments, and with a proper CacheManager implementation leveraging a clustered cache, the Okta Java SDK will live quite happily using this same caching infrastructure.

A coherent cache deployment ensures all of your application instances/nodes can utilize the same cache policy and see the same cached security/identity data. Some example clustered caching solutions: Hazelcast, Ehcache+Terracotta, Memcache, Redis, Coherence, GigaSpaces, etc.

Since:
0.5.0
  • Method Details

    • withDefaultTimeToLive

      CacheManagerBuilder withDefaultTimeToLive(long ttl, TimeUnit timeUnit)
      Sets the default Time to Live (TTL) for all cache regions managed by the built CacheManager. You may override this default for individual cache regions by using the withCache for each region you wish to configure.

      Time to Live is the amount of time a cache entry may exist after first being created before it will expire and no longer be available. If a cache entry ever becomes older than this amount of time (regardless of how often it is accessed), it will be removed from the cache as soon as possible.

      If this value is not configured, it is assumed that cache entries could potentially live indefinitely. Note however that entries can still be expunged due to other conditions (e.g. memory constraints, Time to Idle setting, etc). Usage

           ...withDefaultTimeToLive(30, TimeUnit.MINUTES)...
           ...withDefaultTimeToLive(1, TimeUnit.HOURS)...
       
      Parameters:
      ttl - default Time To Live scalar value
      timeUnit - default Time to Live unit of time
      Returns:
      the builder instance for method chaining.
    • withDefaultTimeToIdle

      CacheManagerBuilder withDefaultTimeToIdle(long tti, TimeUnit timeUnit)
      Sets the default Time to Idle (TTI) for all cache regions managed by the built CacheManager. You may override this default for individual cache regions by using the withCache for each region you wish to configure.

      Time to Idle is the amount of time a cache entry may be idle (unused / not accessed) before it will expire and no longer be available. If a cache entry is not accessed at all after this amount of time, it will be removed from the cache as soon as possible.

      If this value is not configured, it is assumed that cache entries could potentially live indefinitely. Note however that entries can still be expunged due to other conditions (e.g. memory constraints, Time to Live setting, etc). Usage

           ...withDefaultTimeToLive(30, TimeUnit.MINUTES)...
           ...withDefaultTimeToLive(1, TimeUnit.HOURS)...
       
      Parameters:
      tti - default Time To Idle scalar value
      timeUnit - default Time to Idle unit of time
      Returns:
      the builder instance for method chaining.
    • withCache

      Adds configuration settings for a specific Cache region managed by the built CacheManager, like the region's Time to Live and Time to Idle.
      Parameters:
      builder - the CacheConfigurationBuilder instance that will be used to a cache's configuration.
      Returns:
      this instance for method chaining.
    • build

      CacheManager build()
      Returns a new CacheManager instance reflecting Builder's current configuration.
      Returns:
      a new CacheManager instance reflecting Builder's current configuration.