Class CachedSupplier<T>
- java.lang.Object
-
- software.amazon.awssdk.utils.cache.CachedSupplier<T>
-
- All Implemented Interfaces:
AutoCloseable
,Supplier<T>
,SdkAutoCloseable
public class CachedSupplier<T> extends Object implements Supplier<T>, SdkAutoCloseable
A wrapper for aSupplier
that applies certain caching rules to the retrieval of its value, including customizable pre-fetching behaviors for updating values as they get close to expiring so that not all threads have to block to update the value. For example, theOneCallerBlocks
strategy will have a single caller block to update the value, and theNonBlocking
strategy maintains a thread pool for updating the value asynchronously in the background. This should be created usingbuilder(Supplier)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CachedSupplier.Builder<T>
A Builder forCachedSupplier
, created bybuilder(Supplier)
.static interface
CachedSupplier.PrefetchStrategy
The way in which the cache should be pre-fetched when the data'sRefreshResult.prefetchTime()
arrives.static class
CachedSupplier.StaleValueBehavior
How the cached supplier should behave when a stale value is retrieved from the underlying supplier or the underlying supplier fails while the cached value is stale.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> CachedSupplier.Builder<T>
builder(Supplier<RefreshResult<T>> valueSupplier)
Retrieve a builder that can be used for creating aCachedSupplier
.void
close()
Free any resources consumed by the prefetch strategy this supplier is using.T
get()
-
-
-
Method Detail
-
builder
public static <T> CachedSupplier.Builder<T> builder(Supplier<RefreshResult<T>> valueSupplier)
Retrieve a builder that can be used for creating aCachedSupplier
.- Parameters:
valueSupplier
- The value supplier that should have its value cached.
-
close
public void close()
Free any resources consumed by the prefetch strategy this supplier is using.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSdkAutoCloseable
-
-