public class DefaultCacheManager extends Object implements 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.
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.
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.
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.
Modifier and Type | Field and Description |
---|---|
protected ConcurrentMap<String,Cache> |
caches
Retains all Cache objects maintained by this cache manager.
|
Constructor and Description |
---|
DefaultCacheManager()
Default no-arg constructor that instantiates an internal name-to-cache
ConcurrentMap . |
Modifier and Type | Method and Description |
---|---|
protected Cache |
createCache(String name)
Creates a new
Cache instance associated with the specified name . |
<K,V> Cache<K,V> |
getCache(String name)
Returns the cache with the specified
name . |
Duration |
getDefaultTimeToIdle()
Returns the default
timeToIdle duration
to apply to newly created DefaultCache instances. |
Duration |
getDefaultTimeToLive()
Returns the default
timeToLive duration
to apply to newly created DefaultCache instances. |
void |
setCacheConfigurations(Collection<CacheConfiguration> configs)
Sets cache-specific configuration entries, to be utilized when creating cache instances.
|
void |
setDefaultTimeToIdle(Duration defaultTimeToIdle)
Sets the default
timeToIdle duration
to apply to newly created DefaultCache instances. |
void |
setDefaultTimeToIdleSeconds(long seconds)
|
void |
setDefaultTimeToLive(Duration defaultTimeToLive)
Sets the default
timeToLive duration
to apply to newly created DefaultCache instances. |
void |
setDefaultTimeToLiveSeconds(long seconds)
|
String |
toString() |
protected final ConcurrentMap<String,Cache> caches
public DefaultCacheManager()
ConcurrentMap
.public Duration getDefaultTimeToLive()
timeToLive
duration
to apply to newly created DefaultCache
instances. This setting does not affect existing
DefaultCache
instances.timeToLive
duration
to apply to newly created DefaultCache
instances.DefaultCache
,
DefaultCache.getTimeToLive()
public void setDefaultTimeToLive(Duration defaultTimeToLive)
timeToLive
duration
to apply to newly created DefaultCache
instances. This setting does not affect existing
DefaultCache
instances.defaultTimeToLive
- the default timeToLive
duration to apply to newly created DefaultCache
instances.public void setDefaultTimeToLiveSeconds(long seconds)
seconds
- the defaultTimeToLive
value in seconds.public Duration getDefaultTimeToIdle()
timeToIdle
duration
to apply to newly created DefaultCache
instances. This setting does not affect existing
DefaultCache
instances.timeToIdle
duration
to apply to newly created DefaultCache
instances.public void setDefaultTimeToIdle(Duration defaultTimeToIdle)
timeToIdle
duration
to apply to newly created DefaultCache
instances. This setting does not affect existing
DefaultCache
instances.defaultTimeToIdle
- the default timeToIdle
duration to apply to newly created DefaultCache
instances.public void setDefaultTimeToIdleSeconds(long seconds)
seconds
- the defaultTimeToIdle
value in seconds.public void setCacheConfigurations(Collection<CacheConfiguration> configs)
configs
- cache-specific configuration entries, to be utilized when creating cache instances.public <K,V> Cache<K,V> getCache(String name) throws IllegalArgumentException
name
. If the cache instance does not yet exist, it will be lazily
created, retained for further access, and then returned.getCache
in interface CacheManager
K
- type of cache keyV
- type of cache valuename
- the name of the cache to acquire.name
.IllegalArgumentException
- if the name
argument is null
or does not contain text.protected Cache createCache(String name)
Cache
instance associated with the specified name
.name
- the name of the cache to createCache
instance associated with the specified name
.Copyright © 2017–2023 Okta. All rights reserved.