Class CachedResource<R>
java.lang.Object
io.github.thecsdev.tcdcommons.api.util.io.cache.CachedResource<R>
Provides information about a resource that has successfully been fetched
via
IResourceFetchTask.fetchResourceSync()
.-
Constructor Summary
ConstructorDescriptionCachedResource
(R resource, long resourceSizeB, Instant expirationDate) Creates an instance ofCachedResource
. -
Method Summary
Modifier and TypeMethodDescriptionfinal Instant
Returns the time at which thisCachedResource
will be considered as "expired".final R
Returns the fetched resource itself.final long
Returns the "size" of the resource, aka the amount of RAM memory the resource takes up.Returns theClass
instance representing the type of theCachedResource
.static final CachedResource<byte[]>
Creates aCachedResource
instance forByte
arrays.static final CachedResource<String>
Creates aCachedResource
instance forString
s.
-
Constructor Details
-
CachedResource
public CachedResource(R resource, long resourceSizeB, Instant expirationDate) throws NullPointerException Creates an instance ofCachedResource
.- Parameters:
resource
- The resource that is being cached.resourceSizeB
- The amount of space the resource takes up in RAM, in bytes.expirationDate
- The time in the future, at which the resource will expire.- Throws:
NullPointerException
- If an argument isnull
.
-
-
Method Details
-
getResourceType
Returns theClass
instance representing the type of theCachedResource
. -
getResource
Returns the fetched resource itself. -
getResourceSizeB
public final long getResourceSizeB()Returns the "size" of the resource, aka the amount of RAM memory the resource takes up. Measured in bytes. -
getExpirationDate
Returns the time at which thisCachedResource
will be considered as "expired". -
ofString
public static final CachedResource<String> ofString(String text, Instant expirationDate) throws NullPointerException Creates aCachedResource
instance forString
s.- Parameters:
text
- TheString
representing the resource.- Throws:
NullPointerException
- If the argument isnull
.
-
ofBytes
public static final CachedResource<byte[]> ofBytes(byte[] bytes, Instant expirationDate) throws NullPointerException Creates aCachedResource
instance forByte
arrays.- Parameters:
bytes
- TheByte
array representing the resource.- Throws:
NullPointerException
- If the argument isnull
.
-