Class DefaultCacheManager

java.lang.Object
com.okta.sdk.impl.cache.DefaultCacheManager
All Implemented Interfaces:
CacheManager

public class DefaultCacheManager extends Object implements CacheManager
Very simple default CacheManager implementation that retains all created Cache instances in an in-memory ConcurrentMap. By default, this implementation creates thread-safe DefaultCache instances via the createCache(name) method, but this can be overridden by subclasses that wish to provide different Cache implementations.

Clustering

This implementation DOES NOT SUPPORT CLUSTERING.

If your application is deployed on multiple hosts, it is strongly recommended that you configure the Okta SDK with a clustered CacheManager implementation so all of your application instances can utilize the same cache policy and see the same security/identity data. Some example clusterable caching projects: Hazelcast, Ehcache+Terracotta, Coherence, GigaSpaces, etc.

This implementation is production-quality, but only recommended for single-node/single-JVM applications.

Time To Idle

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.

This implementation's defaultTimeToIdle is null, which means that cache entries can potentially remain idle indefinitely. Note however that a cache entry can still be expunged due to other conditions (e.g. memory constraints, Time to Live setting, etc).

The defaultTimeToIdle setting is only applied to newly created Cache instances. It does not affect already existing Caches.

Time to Live

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.

This implementation's defaultTimeToLive is null, which means that cache entries could potentially live indefinitely. Note however that a cache entry can still be expunged due to other conditions (e.g. memory constraints, Time to Idle setting, etc).

The defaultTimeToLive setting is only applied to newly created Cache instances. It does not affect already existing Caches.

Thread Safety

This implementation and the cache instances it creates are thread-safe and usable in concurrent environments.
Since:
0.5.0
See Also:
  • Field Details

    • caches

      protected final ConcurrentMap<String,Cache> caches
      Retains all Cache objects maintained by this cache manager.
  • Constructor Details

    • DefaultCacheManager

      public DefaultCacheManager()
      Default no-arg constructor that instantiates an internal name-to-cache ConcurrentMap.
  • Method Details

    • getDefaultTimeToLive

      public Duration getDefaultTimeToLive()
      Returns the default timeToLive duration to apply to newly created DefaultCache instances. This setting does not affect existing DefaultCache instances.
      Returns:
      the default timeToLive duration to apply to newly created DefaultCache instances.
      See Also:
    • setDefaultTimeToLive

      public void setDefaultTimeToLive(Duration defaultTimeToLive)
      Sets the default timeToLive duration to apply to newly created DefaultCache instances. This setting does not affect existing DefaultCache instances.
      Parameters:
      defaultTimeToLive - the default timeToLive duration to apply to newly created DefaultCache instances.
    • setDefaultTimeToLiveSeconds

      public void setDefaultTimeToLiveSeconds(long seconds)
      Convenience method that sets the defaultTimeToLive value using a TimeUnit of TimeUnit.SECONDS.
      Parameters:
      seconds - the defaultTimeToLive value in seconds.
    • getDefaultTimeToIdle

      public Duration getDefaultTimeToIdle()
      Returns the default timeToIdle duration to apply to newly created DefaultCache instances. This setting does not affect existing DefaultCache instances.
      Returns:
      the default timeToIdle duration to apply to newly created DefaultCache instances.
    • setDefaultTimeToIdle

      public void setDefaultTimeToIdle(Duration defaultTimeToIdle)
      Sets the default timeToIdle duration to apply to newly created DefaultCache instances. This setting does not affect existing DefaultCache instances.
      Parameters:
      defaultTimeToIdle - the default timeToIdle duration to apply to newly created DefaultCache instances.
    • setDefaultTimeToIdleSeconds

      public void setDefaultTimeToIdleSeconds(long seconds)
      Convenience method that sets the defaultTimeToIdle value using a TimeUnit of TimeUnit.SECONDS.
      Parameters:
      seconds - the defaultTimeToIdle value in seconds.
    • setCacheConfigurations

      public void setCacheConfigurations(Collection<CacheConfiguration> configs)
      Sets cache-specific configuration entries, to be utilized when creating cache instances.
      Parameters:
      configs - cache-specific configuration entries, to be utilized when creating cache instances.
    • getCache

      public <K, V> Cache<K,V> getCache(String name) throws IllegalArgumentException
      Returns the cache with the specified name. If the cache instance does not yet exist, it will be lazily created, retained for further access, and then returned.
      Specified by:
      getCache in interface CacheManager
      Type Parameters:
      K - type of cache key
      V - type of cache value
      Parameters:
      name - the name of the cache to acquire.
      Returns:
      the cache with the specified name.
      Throws:
      IllegalArgumentException - if the name argument is null or does not contain text.
    • createCache

      protected Cache createCache(String name)
      Creates a new Cache instance associated with the specified name.
      Parameters:
      name - the name of the cache to create
      Returns:
      a new Cache instance associated with the specified name.
    • toString

      public String toString()
      Overrides:
      toString in class Object