Class HttpProfileCache.CacheBucketMeta
java.lang.Object
com.thecsdev.common.resource.http.HttpProfileCache.CacheBucketMeta
- Enclosing class:
HttpProfileCache
Represents metadata for a
HttpProfileCache.CacheBucket, such as expiration time.
This metadata is stored in a "meta.json" file within the HttpProfileCache.CacheBucket
directory.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal @NotNull PathThePathto the metadata file of thisHttpProfileCache.CacheBucketMeta.final longThe maximum age (in seconds) a cached resource may exist before being considered as "expired".getVary()The "Vary" header values associated with aHttpProfileCache.CacheBucket.final voidLoads thisHttpProfileCache.CacheBucketMetafrom the file specified byfilename.final voidloadFromJson(@NotNull com.google.gson.JsonObject from) Loads thisHttpProfileCache.CacheBucketMetafrom aJsonObject, overriding any properties of thisJsonConfigthat were stored in theJsonObject.final @NotNull PathresolveCacheFile(@NotNull ResourceRequest request) Resolves the cache file path for the givenResourceRequest, based on the "Vary" header values stored in thisHttpProfileCache.CacheBucketMeta.final voidSaves thisHttpProfileCache.CacheBucketMetato the file specified byfilename.final @NotNull com.google.gson.JsonObjectSaves thisHttpProfileCache.CacheBucketMetainstance to a newJsonObjectinstance and returns theJsonObject.final voidsaveToJson(@NotNull com.google.gson.JsonObject to) Saves thisHttpProfileCache.CacheBucketMetato an existingJsonObjectinstance.final voidsetMaxAge(long maxAge) Sets the maximum age (in seconds) for thisHttpProfileCache.CacheBucketMeta.final voidsetVary(@NotNull Collection<String> varyHeaders) Sets the "Vary" header values for thisHttpProfileCache.CacheBucketMeta.
-
Constructor Details
-
CacheBucketMeta
public CacheBucketMeta(@NotNull @NotNull HttpProfileCache.CacheBucket cacheBucket) throws NullPointerException - Throws:
NullPointerException
-
-
Method Details
-
getFilename
ThePathto the metadata file of thisHttpProfileCache.CacheBucketMeta. -
getMaxAge
public final long getMaxAge()The maximum age (in seconds) a cached resource may exist before being considered as "expired". -
getVary
The "Vary" header values associated with aHttpProfileCache.CacheBucket. The returnedCollectionis sorted and immutable. -
setMaxAge
public final void setMaxAge(long maxAge) Sets the maximum age (in seconds) for thisHttpProfileCache.CacheBucketMeta. The value is clamped to a minimum of 0.- Parameters:
maxAge- The maximum age in seconds.
-
setVary
public final void setVary(@NotNull @NotNull Collection<String> varyHeaders) throws NullPointerException Sets the "Vary" header values for thisHttpProfileCache.CacheBucketMeta. The provided collection is sorted and stored as an immutable list.- Parameters:
varyHeaders- The collection of "Vary" header values to set.- Throws:
NullPointerException- If the argument isnull.
-
saveToJson
@NotNull public final @NotNull com.google.gson.JsonObject saveToJson()Saves thisHttpProfileCache.CacheBucketMetainstance to a newJsonObjectinstance and returns theJsonObject. -
saveToJson
public final void saveToJson(@NotNull @NotNull com.google.gson.JsonObject to) throws NullPointerException Saves thisHttpProfileCache.CacheBucketMetato an existingJsonObjectinstance.- Parameters:
to- TheJsonObjectto save to.- Throws:
NullPointerException- If the argument isnull.
-
loadFromJson
public final void loadFromJson(@NotNull @NotNull com.google.gson.JsonObject from) throws NullPointerException Loads thisHttpProfileCache.CacheBucketMetafrom aJsonObject, overriding any properties of thisJsonConfigthat were stored in theJsonObject.- Parameters:
from- TheJsonObjectto load from.- Throws:
NullPointerException- If the argument isnull.
-
saveToFile
Saves thisHttpProfileCache.CacheBucketMetato the file specified byfilename.- Throws:
IOException- If an I/O error occurs while writing to the file.
-
loadFromFile
Loads thisHttpProfileCache.CacheBucketMetafrom the file specified byfilename. If the file does not exist, this method does nothing.- Throws:
IOException- If an I/O error occurs while reading from the file or parsing its contents.
-
resolveCacheFile
@NotNull public final @NotNull Path resolveCacheFile(@NotNull @NotNull ResourceRequest request) throws NullPointerException Resolves the cache file path for the givenResourceRequest, based on the "Vary" header values stored in thisHttpProfileCache.CacheBucketMeta. The returned path is relative to theHttpProfileCache.CacheBucketdirectory.- Parameters:
request- TheResourceRequestfor which to resolve the cache file path.- Throws:
NullPointerException- If the argument isnull.
-