Class Caches
- java.lang.Object
-
- com.okta.sdk.cache.Caches
-
public class Caches extends java.lang.ObjectStatic utility/helper factory methods for buildingCacheManagers 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
CacheManagerAPI directly to use your distributed/clustered cache technology of choice.See the
CacheManagerBuilderJavaDoc for more information the effects of caching in single-jvm vs distributed-jvm applications.Usage Example
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 CacheManagerThe 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.
- Since:
- 0.5.0
-
-
Constructor Summary
Constructors Constructor Description Caches()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Resource>
CacheConfigurationBuilderforResource(java.lang.Class<T> clazz)Returns a newCacheConfigurationBuilderto configure a cache region that will store data for instances of typeclazz.static CacheConfigurationBuildernamed(java.lang.String name)Returns a newCacheConfigurationBuilderused to configure a cache region with the specified name.static CacheManagerBuildernewCacheManager()Instantiates a newCacheManagerBuildersuitable for SINGLE-JVM APPLICATIONS.static CacheManagernewDisabledCacheManager()Instantiates a newCacheManagerthat disables caching entirely.
-
-
-
Method Detail
-
newCacheManager
public static CacheManagerBuilder newCacheManager()
Instantiates a newCacheManagerBuildersuitable 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 theCacheManagerAPI directly to use your distributed/clustered cache technology of choice.See the
CacheManagerBuilderJavaDoc for more information the effects of caching in single-jvm vs distributed-jvm applications.- Returns:
- a new
CacheManagerBuildersuitable for SINGLE-JVM APPLICATIONS.
-
newDisabledCacheManager
public static CacheManager newDisabledCacheManager()
Instantiates a newCacheManagerthat 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.- Returns:
- a new disabled
CacheManagerinstance. All caching
-
forResource
public static <T extends Resource> CacheConfigurationBuilder forResource(java.lang.Class<T> clazz)
Returns a newCacheConfigurationBuilderto configure a cache region that will store data for instances of typeclazz.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();- Type Parameters:
T- Resource sub-interface- Parameters:
clazz- the resource class that will have a backing cache region for storing data of that type- Returns:
- a new
CacheConfigurationBuilderto configure a cache region that will store data for instances of typeclazz.
-
named
public static CacheConfigurationBuilder named(java.lang.String name)
Returns a newCacheConfigurationBuilderused 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();- Parameters:
name- the name of the cache region for which the configuration will apply- Returns:
- a new
CacheConfigurationBuilderused to configure a cache region with the specified name.
-
-