public class Caches
extends java.lang.Object
CacheManager
s and their associated cache regions, suitable for SINGLE-JVM APPLICATIONS.
If your application is deployed on multiple JVMs (e.g. a distributed/clustered web app), you might not want to
use the builders here and instead implement the CacheManager
API directly to use your distributed/clustered
cache technology of choice.
See the CacheManagerBuilder
JavaDoc for more information the effects of caching in
single-jvm vs distributed-jvm applications.
import static com.okta.sdk.cache.Caches.*; ... Caches.newCacheManager()
.withDefaultTimeToLive(1, TimeUnit.DAYS) //general default .withDefaultTimeToIdle(2, TimeUnit.HOURS) //general default .withCache(forResource
(Account.class) //Account-specific cache settings .withTimeToLive(1, TimeUnit.HOURS) .withTimeToIdle(30, TimeUnit.MINUTES)) .withCache(forResource
(Group.class) //Group-specific cache settings .withTimeToLive(2, TimeUnit.HOURS)) // ... etc ... .build(); //build the CacheManager
The above TTL and TTI times are just examples showing API usage - the times themselves are not recommendations. Choose TTL and TTI times based on your application requirements.
Constructor and Description |
---|
Caches() |
Modifier and Type | Method and Description |
---|---|
static <T> CacheConfigurationBuilder |
forResource(java.lang.Class<T> clazz)
Returns a new
CacheConfigurationBuilder to configure a cache region that will store data for instances
of type clazz . |
static CacheConfigurationBuilder |
named(java.lang.String name)
Returns a new
CacheConfigurationBuilder used to configure a cache region with the specified name. |
static CacheManagerBuilder |
newCacheManager()
Instantiates a new
CacheManagerBuilder suitable for SINGLE-JVM APPLICATIONS. |
static CacheManager |
newDisabledCacheManager()
Instantiates a new
CacheManager that disables caching entirely. |
public static CacheManagerBuilder newCacheManager()
CacheManagerBuilder
suitable for SINGLE-JVM APPLICATIONS. If your application
is deployed on multiple JVMs (e.g. for a distributed/clustered web app), you might not want to use this method
and instead implement the CacheManager
API directly to use your distributed/clustered cache technology
of choice.
See the CacheManagerBuilder
JavaDoc for more information the effects of caching in
single-jvm vs distributed-jvm applications.
CacheManagerBuilder
suitable for SINGLE-JVM APPLICATIONS.public static CacheManager newDisabledCacheManager()
CacheManager
that disables caching entirely. While production applications
will usually enable a working CacheManager, you might configure a disabled CacheManager for
your Client when testing or debugging to remove 'moving parts' for better clarity into request/response
behavior.CacheManager
instance. All cachingpublic static <T> CacheConfigurationBuilder forResource(java.lang.Class<T> clazz)
CacheConfigurationBuilder
to configure a cache region that will store data for instances
of type clazz
.
This is a convenience method equivalent to named(clazz.getName())
, but it could help
with readability, for example:
import static com.okta.sdk.cache.Caches.* ... newCacheManager() .withCache(forResource(Account.class).withTimeToIdle(10, TimeUnit.MINUTES)) .build();
T
- Resource sub-interfaceclazz
- the resource class that will have a backing cache region for storing data of that typeCacheConfigurationBuilder
to configure a cache region that will store data for instances
of type clazz
.public static CacheConfigurationBuilder named(java.lang.String name)
CacheConfigurationBuilder
used to configure a cache region with the specified name. For
example:
import static com.okta.sdk.cache.Caches.* ... newCacheManager() .withCache(named("myCacheRegion").withTimeToIdle(10, TimeUnit.MINUTES)) .build();
name
- the name of the cache region for which the configuration will applyCacheConfigurationBuilder
used to configure a cache region with the specified name.Copyright © 2017-2022 Okta. All Rights Reserved.