Class HttpProfileCache
java.lang.Object
com.thecsdev.common.resource.http.HttpProfileCache
Represents a "cache" for storing cached HTTP resources.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classRepresents a directory where cache data for a givenURIis stored.static final classRepresents metadata for aHttpProfileCache.CacheBucket, such as expiration time. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanfinal CompletableFuture<@Nullable ResourceResponse> fetchAsync(@NotNull ResourceRequest request) Fetches the cachedResourceResponsefor the givenResourceRequest, if it exists and is valid.final @NotNull PathReturns thePathto the directory where theHttpProfileCachedata and cached HTTP resources are stored.static final @NotNull PathGenerates relative a cache path for the givenResourceRequest, based on the given hash.final inthashCode()CompletableFuture<@Nullable Void> storeAsync(@NotNull ResourceRequest request, @NotNull ResourceResponse response) Stores the givenResourceResponsein the cache for the givenResourceRequest.
-
Field Details
-
GSON
@Internal public static final com.google.gson.Gson GSON
-
-
Constructor Details
-
HttpProfileCache
- Throws:
NullPointerException
-
-
Method Details
-
hashCode
-
equals
-
getDirname
Returns thePathto the directory where theHttpProfileCachedata and cached HTTP resources are stored. -
fetchAsync
public final CompletableFuture<@Nullable ResourceResponse> fetchAsync(@NotNull @NotNull ResourceRequest request) throws NullPointerException Fetches the cachedResourceResponsefor the givenResourceRequest, if it exists and is valid. Returns aCompletableFuturethat completes with the cached response, ornullthe cache is a "miss".- Parameters:
request- TheResourceRequestfor which to fetch the cached response.- Throws:
NullPointerException- If the argument isnull.
-
storeAsync
public CompletableFuture<@Nullable Void> storeAsync(@NotNull @NotNull ResourceRequest request, @NotNull @NotNull ResourceResponse response) throws NullPointerException Stores the givenResourceResponsein the cache for the givenResourceRequest. Returns aCompletableFuturethat completes when the response has been stored.- Parameters:
request- TheResourceRequestassociated with the response to store.response- TheResourceResponseto store in the cache.- Throws:
NullPointerException- If an argument isnull.
-
hash2path
@NotNull public static final @NotNull Path hash2path(@NotNull @NotNull String hash) throws NullPointerException Generates relative a cache path for the givenResourceRequest, based on the given hash. The path is structured to provide directory nesting based on the hash.- Throws:
NullPointerException
-