Package swervelib.parser
Class Cache<T>
java.lang.Object
swervelib.parser.Cache<T>
Cache for frequently requested data.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetValue()Get the most up to date cached value.booleanisStale()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:
Cacheused.
-
updateSupplier
Update the supplier to a new source. Updates the value and timestamp as well.- Parameters:
supplier- new supplier source.- Returns:
Cachefor chaining.
-
updateValidityPeriod
Update the validity period for the cached value, also updates the value.- Parameters:
validityPeriod- The new validity period in milliseconds.- Returns:
Cachefor chaining.
-
getValue
Get the most up to date cached value.- Returns:
Cacheupdated to the latest cached version.
-