Class Cache<T>

java.lang.Object
swervelib.parser.Cache<T>

public class Cache<T> extends Object
Cache for frequently requested data.
  • Constructor Details

    • Cache

      public Cache(Supplier<T> val, long validityPeriod)
      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

      public Cache<T> update()
      Update the cache value and timestamp.
      Returns:
      Cache used.
    • updateSupplier

      public Cache<T> updateSupplier(Supplier<T> supplier)
      Update the supplier to a new source. Updates the value and timestamp as well.
      Parameters:
      supplier - new supplier source.
      Returns:
      Cache for chaining.
    • updateValidityPeriod

      public Cache<T> updateValidityPeriod(long validityPeriod)
      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

      public T getValue()
      Get the most up to date cached value.
      Returns:
      Cache updated to the latest cached version.