Class DefaultCacheManager
- All Implemented Interfaces:
CacheManager
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 Cache
s.
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 Cache
s.
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 Summary
Modifier and TypeFieldDescriptionprotected final ConcurrentMap
<String, Cache> Retains all Cache objects maintained by this cache manager. -
Constructor Summary
ConstructorDescriptionDefault no-arg constructor that instantiates an internal name-to-cacheConcurrentMap
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Cache
createCache
(String name) Creates a newCache
instance associated with the specifiedname
.<K,
V> Cache <K, V> Returns the cache with the specifiedname
.Returns the defaulttimeToIdle
duration to apply to newly createdDefaultCache
instances.Returns the defaulttimeToLive
duration to apply to newly createdDefaultCache
instances.void
Sets cache-specific configuration entries, to be utilized when creating cache instances.void
setDefaultTimeToIdle
(Duration defaultTimeToIdle) Sets the defaulttimeToIdle
duration to apply to newly createdDefaultCache
instances.void
setDefaultTimeToIdleSeconds
(long seconds) void
setDefaultTimeToLive
(Duration defaultTimeToLive) Sets the defaulttimeToLive
duration to apply to newly createdDefaultCache
instances.void
setDefaultTimeToLiveSeconds
(long seconds) toString()
-
Field Details
-
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-cacheConcurrentMap
.
-
-
Method Details
-
getDefaultTimeToLive
Returns the defaulttimeToLive
duration to apply to newly createdDefaultCache
instances. This setting does not affect existingDefaultCache
instances.- Returns:
- the default
timeToLive
duration to apply to newly createdDefaultCache
instances. - See Also:
-
setDefaultTimeToLive
Sets the defaulttimeToLive
duration to apply to newly createdDefaultCache
instances. This setting does not affect existingDefaultCache
instances.- Parameters:
defaultTimeToLive
- the defaulttimeToLive
duration to apply to newly createdDefaultCache
instances.
-
setDefaultTimeToLiveSeconds
public void setDefaultTimeToLiveSeconds(long seconds) - Parameters:
seconds
- thedefaultTimeToLive
value in seconds.
-
getDefaultTimeToIdle
Returns the defaulttimeToIdle
duration to apply to newly createdDefaultCache
instances. This setting does not affect existingDefaultCache
instances.- Returns:
- the default
timeToIdle
duration to apply to newly createdDefaultCache
instances.
-
setDefaultTimeToIdle
Sets the defaulttimeToIdle
duration to apply to newly createdDefaultCache
instances. This setting does not affect existingDefaultCache
instances.- Parameters:
defaultTimeToIdle
- the defaulttimeToIdle
duration to apply to newly createdDefaultCache
instances.
-
setDefaultTimeToIdleSeconds
public void setDefaultTimeToIdleSeconds(long seconds) - Parameters:
seconds
- thedefaultTimeToIdle
value in seconds.
-
setCacheConfigurations
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
Returns the cache with the specifiedname
. If the cache instance does not yet exist, it will be lazily created, retained for further access, and then returned.- Specified by:
getCache
in interfaceCacheManager
- Type Parameters:
K
- type of cache keyV
- type of cache value- Parameters:
name
- the name of the cache to acquire.- Returns:
- the cache with the specified
name
. - Throws:
IllegalArgumentException
- if thename
argument isnull
or does not contain text.
-
createCache
Creates a newCache
instance associated with the specifiedname
.- Parameters:
name
- the name of the cache to create- Returns:
- a new
Cache
instance associated with the specifiedname
.
-
toString
-