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 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 Summary
FieldsModifier and TypeFieldDescriptionprotected final ConcurrentMap<String, Cache> Retains all Cache objects maintained by this cache manager. -
Constructor Summary
ConstructorsConstructorDescriptionDefault no-arg constructor that instantiates an internal name-to-cacheConcurrentMap. -
Method Summary
Modifier and TypeMethodDescriptionprotected CachecreateCache(String name) Creates a newCacheinstance associated with the specifiedname.<K,V> Cache <K, V> Returns the cache with the specifiedname.Returns the defaulttimeToIdleduration to apply to newly createdDefaultCacheinstances.Returns the defaulttimeToLiveduration to apply to newly createdDefaultCacheinstances.voidSets cache-specific configuration entries, to be utilized when creating cache instances.voidsetDefaultTimeToIdle(Duration defaultTimeToIdle) Sets the defaulttimeToIdleduration to apply to newly createdDefaultCacheinstances.voidsetDefaultTimeToIdleSeconds(long seconds) voidsetDefaultTimeToLive(Duration defaultTimeToLive) Sets the defaulttimeToLiveduration to apply to newly createdDefaultCacheinstances.voidsetDefaultTimeToLiveSeconds(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 defaulttimeToLiveduration to apply to newly createdDefaultCacheinstances. This setting does not affect existingDefaultCacheinstances.- Returns:
- the default
timeToLiveduration to apply to newly createdDefaultCacheinstances. - See Also:
-
setDefaultTimeToLive
Sets the defaulttimeToLiveduration to apply to newly createdDefaultCacheinstances. This setting does not affect existingDefaultCacheinstances.- Parameters:
defaultTimeToLive- the defaulttimeToLiveduration to apply to newly createdDefaultCacheinstances.
-
setDefaultTimeToLiveSeconds
public void setDefaultTimeToLiveSeconds(long seconds) - Parameters:
seconds- thedefaultTimeToLivevalue in seconds.
-
getDefaultTimeToIdle
Returns the defaulttimeToIdleduration to apply to newly createdDefaultCacheinstances. This setting does not affect existingDefaultCacheinstances.- Returns:
- the default
timeToIdleduration to apply to newly createdDefaultCacheinstances.
-
setDefaultTimeToIdle
Sets the defaulttimeToIdleduration to apply to newly createdDefaultCacheinstances. This setting does not affect existingDefaultCacheinstances.- Parameters:
defaultTimeToIdle- the defaulttimeToIdleduration to apply to newly createdDefaultCacheinstances.
-
setDefaultTimeToIdleSeconds
public void setDefaultTimeToIdleSeconds(long seconds) - Parameters:
seconds- thedefaultTimeToIdlevalue 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:
getCachein 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 thenameargument isnullor does not contain text.
-
createCache
Creates a newCacheinstance associated with the specifiedname.- Parameters:
name- the name of the cache to create- Returns:
- a new
Cacheinstance associated with the specifiedname.
-
toString
-