Class CachedSupplier<T>
java.lang.Object
software.amazon.awssdk.utils.cache.CachedSupplier<T>
- All Implemented Interfaces:
AutoCloseable,Supplier<T>,SdkAutoCloseable
@SdkProtectedApi
public class CachedSupplier<T>
extends Object
implements Supplier<T>, SdkAutoCloseable
A wrapper for a
Supplier 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, the OneCallerBlocks strategy will have a single caller block to update the value, and the
NonBlocking strategy maintains a thread pool for updating the value asynchronously in the background.
This should be created using builder(Supplier).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA Builder forCachedSupplier, created bybuilder(Supplier).static interfaceThe way in which the cache should be pre-fetched when the data'sRefreshResult.prefetchTime()arrives.static enumHow 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
Modifier and TypeMethodDescriptionstatic <T> CachedSupplier.Builder<T> builder(Supplier<RefreshResult<T>> valueSupplier) Retrieve a builder that can be used for creating aCachedSupplier.voidclose()Free any resources consumed by the prefetch strategy this supplier is using.get()
-
Method Details
-
builder
Retrieve a builder that can be used for creating aCachedSupplier.- Parameters:
valueSupplier- The value supplier that should have its value cached.
-
get
-
close
public void close()Free any resources consumed by the prefetch strategy this supplier is using.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSdkAutoCloseable
-