Package swervelib.parser
Class Cache<T>
java.lang.Object
swervelib.parser.Cache<T>
Cache for frequently requested data.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetValue()
Get the most up to date cached value.boolean
isStale()
Return whether the cache is stale.update()
Update the cache value and timestamp.updateSupplier
(Supplier<T> supplier) Update the supplier to a new source.updateValidityPeriod
(long validityPeriod) Update the validity period for the cached value, also updates the value.
-
Constructor Details
-
Cache
Cache for arbitrary values.- Parameters:
val
- Value to cache.validityPeriod
- Validity period in milliseconds.
-
-
Method Details
-
isStale
public boolean isStale()Return whether the cache is stale.- Returns:
- The stale state of the cache.
-
update
Update the cache value and timestamp.- Returns:
Cache
used.
-
updateSupplier
Update the supplier to a new source. Updates the value and timestamp as well.- Parameters:
supplier
- new supplier source.- Returns:
Cache
for chaining.
-
updateValidityPeriod
Update the validity period for the cached value, also updates the value.- Parameters:
validityPeriod
- The new validity period in milliseconds.- Returns:
Cache
for chaining.
-
getValue
Get the most up to date cached value.- Returns:
Cache
updated to the latest cached version.
-